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

0 comments

Please sign in to leave a comment.