Revit secondary development knowledge sharing (4) Calculate the center point of Face

We often encounter that when we need the center point of a surface, the API does not give a direct method, so we need to use geometric knowledge to calculate the center point of a surface. No matter what the shape of the surface is, it is possible to calculate a maximum contour line enclosed by the convex points of the surface.
First code and then explain, Just Do It! ! !

 public static XYZ GetFaceCenter(this Face temFace)
        {
    
    
            var faceBound = temFace.GetBoundingBox();
            UV maxUV = faceBound.Max;
            UV minUV = faceBound.Min;
            UV uvPoint = (maxUV + minUV) / 2;
            XYZ centerPoint = temFace.Evaluate(uvPoint).SetZ();
            return centerPoint;
        }

Explanation:
(1) Get the BoundingBox of this face first
Insert picture description here
Insert picture description here

(2) Take the two vertices of the envelope
Insert picture description here

What needs attention here is. The point we got is in the UV coordinate system, which is a plane composed of the origin of the plane and the U and V directions. Therefore, the values ​​of the coordinate points are not directly the same.
(3) Through the Evaluate method, get the corresponding coordinate point of the UV point on this surface. Get the XYZ coordinates.
That's it for this sharing. Follow me, learn more about secondary development, and continue to update every week. . .

Guess you like

Origin blog.csdn.net/Oneal5354/article/details/108394080