How to retrieve the nearest face of a shape from a given gp_Pnt

I'm trying to make a sort of mecanism of selection and I wanted to select the nearest face from a point.
I tried to use the orthogonal projection of my point on each face of the shape, then compute the distance between the point and the projected point and finally select the face with the distance min. In fact, during this process, I have to compute the famous U,V bounds each face witch define a rectangle and not the outerwire of the face.
The problem is that when I have two coplanar and contiguous triangular faces and depending of my point, I select sometimes the bad face.

I Anyone knows how to get the nearest face by an other way, I'm very interested.

Thanks in advance for your replies,


Rob Bachrach's picture

Create a TopoDS_Vertex from your gp_Pnt and use either BRepExtrema::ExtPF or BRepExtrema::DistShapeShape(only looking at face matches).