Closest point to a STEP object

I'm trying to find the closest point on the surface of an imported STEP object, to an XYZ point in space.

I think using GeomAPI_ProjectPointOnSurf and then NearestPoint would normally work, but the former needs a surface, and doesn't seem to like the AIS_InteractiveContext of my STEP model.

Is there another way of doing it? Can I break up my STEP model into seperate surfaces?

Any help appreciated.

Cheers,
John

Rob Bachrach's picture

Try using BRepExtrema_DistShapeShape. You can use the TopoDS_Shape from your STEP object and create a vertex from your point. This works better than projecting to the surface since surfaces can be infinite and faces are trimmed.

John Chou's picture

Thanks Rob, I'm sure that will work.
I have created my gp_Pnt and set its coordinates. How do I convert it to a vertex? It must be obvious, but the forum is full of examples of doing it the other way round!
gp_Pnt thePoint = BRep_Tool::Pnt(theVertex);

Thanks,
John

Rob Bachrach's picture

When creating a topological entity from scratch (vertex, edge, face, etc.), you usually use the BRepBuilderAPI_MakeXXXX function. So, to create a vertex from a gp_Pnt, use:
TopoDS_Vertex vertex = BRepBuilderAPI_MakeVertex(pt);

John Chou's picture

Thanks for your help Rob.
My closest point detection is working! (-:

John