Closest point on a Solid3D object

To find the closest point on a Solid3D 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 Solid3D face.

ReadSTEP rs = new ReadSTEP("filename.stp");

viewportLayout1.DoWork(rs);

rs.AddToScene(viewportLayout1);
            
Point3D pt = new Point3D(100,100,100);

Joint j1 = new Joint(pt,2,2);

viewportLayout1.Entities.Add(j1,0,Color.Red);

Solid3D s = (Solid3D) rs.Entities[0];

double minDist = double.MaxValue;
Point3D closest = null;

foreach (Solid3D.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);

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

    viewportLayout1.Entities.Add(j2, 0, Color.Blue);
}


Here is the result:

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

Have more questions? Submit a request

1 Comments

  • 0
    Avatar
    Alberto Bencivenni

    In build 9.0.336 this function was added to Nurbs and Ultimate editions of the product. It's called Solid3D.ClosestPointTo() and computes signed distance from object surface.

Please sign in to leave a comment.