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");
model1.DoWork(rs);
rs.AddToScene(model1);
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];
s.Rebuild();
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);

    model1.Entities.Add(j2,Color.Blue);
}

Here is the result:

2016-02-08_16-34-34.png

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

Comments

2 comments
  • 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?

    0
  • Hi Dave,

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

    Thank you for your collaboration. 

    0

Please sign in to leave a comment.