How to decide whether a point lies inside a face, HELP Pls!


Given a 3D point Pt and a face aFace, I'd like to check whether Pt lies inside aFace. I have tried to use the BRepClass_FaceClassifier, but it seems that it doesn't work well since it always return a state "1". Could anyone give me some hints?

Actually, the problem serves for another problem that is to determine whether an angle on a face is convex or not. Any suggestions?

Thanks a lot.


Udo's picture


You could try to use GProp_PEquation. What Angle do you mean? an angle between two edges? You can calculate the angle between two direction as follows:

gp_Dir D1(1,2,3);
gp_Dir D2(3,4,5);
Standard_Real ang = D1.Angle(D2);



Ming's picture

Hi, Udo
Glad to get your suggestion. But I don't think GProp_PEquation might solve the first problem.

The angle, I mean, is the angle between two edges inside the solid. Do you have some suggestions?


Rob Bachrach's picture

Although this might not be the most efficient method, you might try iterating through the faces. For each face, call BRepTools::OuterWire. This will give you the outer edges of the face in Wire order (this assumes no holes). Then, based on the shared vertex between the edges, you can try something like:

Handle(Geom_Curve) hCurve = BRep_Tool::Curve(edge, fFirst, fLast);
hCurve->D1(fFirst, pt, tan1);
if (!point.IsEqual(pt, Precision::Confusion())) {
hCurve->D1(fLast, pt, tan1);
if (edge.Orientation() != TopAbs_FORWARD) tan1 = -tan1;

Do the same thing to get the tangent of the other edge at the same point. Then, compare the tangents as desired. If you need internal wires as well, you might consider building a map of vertexes in the solid and the edges they connect. Then, you can iterate through the map and, for each vertex, compare all edge angles as above.

Ming's picture

Many thanks for you code, Rob. But there still exist some problems listed as below:
1. In your code "pt" should be the given point, but what is "point" in your code? In fact, the problem then become which one corresponds to the parameter of pt, fFirst or fLast?

2. Acting in a similiar way, I can get another tangent direction Tan2 of the other edge and then compute the angle between them, say Angle. But, which one is the angle "INSIDE" the solid, Angle or 2*Pi-Angle? It might has some relations with the direction of the wire?

Could you kindly explain this in detail?

Best regards!

Ming's picture

I see, "point" is the value of hCurve at the parameter "fFirst". Then what's about the second problem.


Rob Bachrach's picture

Yes, pt starts out at the point at the fFirst parameter. If pt ends up not being at the vertex of interest (located at point, sorry for the names), then pt becomes the point at the fLast parameter.

In response to question 2, all your points are on the edge of the solid (none are "inside"). However, you can find out if your shape has concavities. As you work around the edges of the face, compute the cross product of one vector with the next and record the sign of the cross product. If you see the sign change, the vectors are in the opposite direction w.r.t. each other, indicating a change from convex to concave (or vice versa). Finding the particular point of concavity could be more difficult (as there could be several). Your best bet is to perform some comparison between the adjacent edge cross product and the outward pointing face normal.

Ming's picture

Thank you very much. A clever method although it is not so simple to solve such a apparently simple problem. :) I will report my result after implementation.