Closest point on a Solid3D object (v9)

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");


Point3D pt = new Point3D(100,100,100);

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


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:


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


1 comment
  • 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.

    Comment actions Permalink

Please sign in to leave a comment.