Closest point on a Brep object

To find the closest point on a Brep object you need to loop over its faces and with the help of Surface.ClosestPointTo() and PointAt() methods compute the projection of the 3D test point on each Brep face.

ReadSTEP rs = new ReadSTEP("filename.stp");
Point3D pt = new Point3D(100, 100, 100);
Joint j1 = new Joint(pt, 2, 2);
model1.Entities.Add(j1, Color.Red);
Brep s =(Brep)rs.Entities[0];
double minDist = double.MaxValue;
Point3D closest = null;
foreach (Brep.Face face in s.Faces)
    foreach (Surface surface in face.Parametric)
        double u, v;
        surface.ClosestPointTo(pt, out u, out v);

        Point3D proj = surface.PointAt(u, v);

        double distance = proj.DistanceTo(pt);

        if (distance < minDist)
            closest = proj;
            minDist = distance;

if (closest != null)
    Joint j2 = new Joint(closest, 2, 2);

    model1.Entities.Add(new Line(pt, closest),  Color.Blue);


Here is the result:


Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


  • This code seems to be missing something but I'm struggling to understand how to fix it.  When I try this, I have several faces that do not contain a value for '.Parametric'  maybe there is a way to still measure a face even if it has no value under Parametric?? These (non-Parametric) faces are being ignored and I'm not getting the correct measures.  

    Also, I am finding that my measurements are being measured (in some cases) to un-trimmed surfaces that don't actually exist on the solid model.

    any help?

  • Hi Dave,

    Please, open a support ticket for these kinds of issues. 

    Thank you for your collaboration. 


Please sign in to leave a comment.