jianbaoxia
CAD master
Hi Bros, I'm JianBaoXia.
Today I try to check whether a point on a face. I use the BRepClass_FaceClassifier.State() first, and faild.
Then I try to compute the short distance between point and face, and check if the distance shorter than the tolerance.
It seem I make it success.
However, I still curious with why the BRepClass_FaceClassifier.State() faild, maybe my usage was wrong.
There is my Demo:
Today I try to check whether a point on a face. I use the BRepClass_FaceClassifier.State() first, and faild.
Then I try to compute the short distance between point and face, and check if the distance shorter than the tolerance.
It seem I make it success.
However, I still curious with why the BRepClass_FaceClassifier.State() faild, maybe my usage was wrong.
There is my Demo:
Code:
int main()
{
std::string filePath = "C:/Users/14656/Desktop/Program/Open Cascade/Demo/";
// build face and point
gp_Pnt p1(0, 0, 0);
gp_Pnt p2(1, 0, 0);
gp_Pnt p3(1, 1, 0);
gp_Pnt p4(0, 1, 0);
TopoDS_Edge e1 = BRepBuilderAPI_MakeEdge(p1, p2);
TopoDS_Edge e2 = BRepBuilderAPI_MakeEdge(p2, p3);
TopoDS_Edge e3 = BRepBuilderAPI_MakeEdge(p3, p4);
TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(p4, p1);
TopoDS_Wire w = BRepBuilderAPI_MakeWire(e1, e2, e3, e4);
TopoDS_Face f = BRepBuilderAPI_MakeFace(w);
gp_Pnt p(0.5, 0.5, 0);
TopoDS_Vertex v = BRepBuilderAPI_MakeVertex(p);
// use BRepClass_FaceClassifier
BRepClass_FaceClassifier pointChecker(f, p1, Precision::Confusion());
if (pointChecker.State() == TopAbs_IN) std::cout << "Point on the face (BRepClass_FaceClassifier)" << std::endl;
// use distance
Standard_Real dis = BRepExtrema_DistShapeShape(v, f).Value();
if(dis<=BRep_Tool::Tolerance(f)) std::cout << "Point on the face (BRepExtrema_DistShapeShape)" << std::endl;
BRepBuilderAPI_Sewing aSewMaker;
aSewMaker.Add(v);
aSewMaker.Add(f);
aSewMaker.Perform();
TopoDS_Shape aSewShape = aSewMaker.SewedShape();
WriteStepFile(aSewShape, filePath + "aSewShape.step");
return 0;
}