Nearest point

Hi All,
I create a table of points by TopTools_Array1OfShape.
Is there any algorithm or OCC class to find the nearest point in the table to my arbitrary point(mypoint)?
Thanks for any idea.
Tony

Rob Bachrach's picture

There is no algorithm I know of to work off the array. There are two options that I see (assuming your indeed has TopoDS_Vertex objects):

1-Iterate through the array and keep the one with the minimum distance. So, if you have a gp_Pnt (myPoint), you can call
myPoint.Distance(BRep_Tool::Pnt(myTable(i))) to get the distance. Note that it is even more efficient to use SquareDistance instead of Distance.

2-You can also put all the vertices in a compound. Then, you simply need to use BRepExtrema_DistShapeShape to get the nearest. Note, however, that this will only give you the nearest vertex, not the index into your array (if that is important).

Tony's picture

Hi Sir,
So thank you.
Regards,
Akbari