Mon, 06/10/2024 - 20:39
Forums:
Hi, all. I am really stuck and cannot find the reason what I am doing wrong :( I am trying to create a face, which technically is half cylinder with 3 mm distance. The code below is what I am trying to use, but the face is wrong. I don't understand what I am missing. The last lines supposed not to ASSERT at all. Can you help me? I really will appreciate this.
TopoDS_Face TheFace;
gp_Pnt pt(0.0, 0.0, 0.0);
gp_Dir dir(0.0, 0.0, 1.0);
gp_Ax3 ax(pt, dir, gp_Dir(1.0, 0.0, 0.0));
gp_Cylinder cyl(ax, 5.0);//radius
TopoDS_Wire Outwire;
BRepBuilderAPI_MakeWire mkWire;
{
TopoDS_Edge e1, e2, e3, e4;
{
gp_Pnt oP1(-5.0, 0.0, 0.0);
gp_Pnt oP2(0.0, -5.0, 0.0);
gp_Pnt oP3(5.0, 0.0, 0.0);
GC_MakeArcOfCircle mac(oP1, oP2, oP3);
e1 = BRepBuilderAPI_MakeEdge(mac.Value());
}
{
cD3DPoint P1(5.0, 0.0, 0.0);
cD3DPoint P2(5.0, 0.0, 3.0);
gp_Dir V(P2.x - P1.x, P2.y - P1.y, P2.z - P1.z);
Handle_Geom_Line theCurve = new Geom_Line(gp_Pnt(P1.x, P1.y, P1.z), V);
Handle_Geom_TrimmedCurve TrimCurve = new Geom_TrimmedCurve(theCurve, 0.0, (P2 - P1).GetLength());
e2 = BRepBuilderAPI_MakeEdge(TrimCurve);
}
{
gp_Pnt oP1(5.0, 0.0, 3.0);
gp_Pnt oP2(0.0, -5.0, 3.0);
gp_Pnt oP3(-5.0, 0.0, 3.0);
GC_MakeArcOfCircle mac(oP1, oP2, oP3);
e3 = BRepBuilderAPI_MakeEdge(mac.Value());
}
{
cD3DPoint P1(-5.0, 0.0, 3.0);
cD3DPoint P2(-5.0, 0.0, 0.0);
gp_Dir V(P2.x - P1.x, P2.y - P1.y, P2.z - P1.z);
Handle_Geom_Line theCurve = new Geom_Line(gp_Pnt(P1.x, P1.y, P1.z), V);
Handle_Geom_TrimmedCurve TrimCurve = new Geom_TrimmedCurve(theCurve, 0.0, (P2 - P1).GetLength());
e4 = BRepBuilderAPI_MakeEdge(TrimCurve);
}
mkWire.Add(e1);
mkWire.Add(e2);
mkWire.Add(e3);
mkWire.Add(e4);
Outwire = mkWire.Wire();
}
BRepBuilderAPI_MakeFace makeface(cyl, Outwire);
TheFace = makeface.Face();
gp_Pnt2d np(FLT_MAX, FLT_MAX);
BRepClass_FaceClassifier fc;
fc.Perform(TheFace, np, FLT_EPSILON);
if (fc.State() == TopAbs_IN)
{
ASSERT(FALSE);
}
Tue, 06/11/2024 - 09:28
BRepBuilderAPI_MakeFace
takinggp_Cylinder
implicitly createsGeom_CylindricalSurface
and behaves the same as method takingGeom_Surface
on input. Please pay attention to it's description:The Edges in Wire should define P-Curves (2D curves on your
Geom_CylindricalSurface
) to form a valid Face. But your current logic creates only 3D curves for Edges, which is not enough.If you will pass created Face through
checkshape
tool, it will report 'No Curve on Surface' issue.Tue, 06/11/2024 - 11:21
Thank you very much for the quick and clear answer. It all makes sense now. Do you have any suggestions - how can I resolve this issue? Do I need to project the 3d curves on the surface and then use Geom2d_Curve to create the edge? What is the best workflow for the example like this one. I really appreciate your help.
Tue, 06/11/2024 - 12:05
You may use 3 ways to generate a valid shape, which one to use depends on requirements of your application.
BRepLib::BuildCurve3d()
. This might be more or less robust way.Tue, 06/11/2024 - 12:31
I used your second proposal and it works. All that you say makes huge sense and I hope this article will help others too. Большое спасибо.
Tue, 06/11/2024 - 13:35
Can you help me a bit more :( I am trying to create the cylinder, but want to make a trimmed cylinder - so I need to pass top circle and bottom circle (not arc shape). can you advice - how can I use Makeface in this case? It fails despite I project the circles on the cylinder.
Tue, 06/11/2024 - 14:00
Maybe you can share a new code snippet with the problem...
Tue, 06/11/2024 - 14:36
This is the code I am trying to use:
Tue, 06/11/2024 - 14:37
Also, the projection code I found on internet also:
Tue, 06/11/2024 - 16:37
Please update your comments with HTML styling and inserting code snipped. It is difficult to analyze as a general text.
If you have no permission - i will update, but please next comments write with code snippeds.
Best regards, Dmitrii,
Tue, 06/11/2024 - 16:57
I am sorry, I just pasted as normal text. I can try, but if you can do this would be easier. Thank you very much.
Tue, 06/11/2024 - 17:01
Updated.
Tue, 06/11/2024 - 17:09
I am confused - why you create two Wires from circles? One Wire in the Face is supposed to define outer boundaries and others - holes. But I don't think you want to define a hole here.
Note that for making closed cylindrical Face you'll need defining a seam Edge. It might be helpful learning how to build simple topology and geometry in DRAW harness and displaying it in axonometric view - could help to understand how valid geomtry normally looks alike in OCCT.