To get the average plane I think to get the average center, then edge by edge do a cross product between edge vector and the vector from the center to the edge, then get the average normal from all cross products, it should be the average plane normal, the same used in flatten. I'm not completely sure, haven't tested it…