Conical surface

I'm trying to make a conical surface bounded by two lines and a circular arc. Here is a sample code

double h = 20.0;
double a = 60.0 * (M_PI / 180.0);
double dh = h * tan(a / 1.0);
double r = dh;

gp_Dir aDir(0.0, 0.0, 1.0);

gp_Pnt aPnt0(0.0,           0,              0.0          );
gp_Pnt aPnt1(dh,            0,              aPnt0.Z() + h);
gp_Pnt aPnt2(0,             dh,             aPnt0.Z() + h);

//
gp_Circ circ(gp_Ax2(gp_Pnt(0.0, 0.0, aPnt0.Z() + h), aDir, gp_Dir(1.0, 0.0, 0.0)), r);
Handle(Geom_TrimmedCurve) aArc = GC_MakeArcOfCircle(circ, aPnt1, aPnt2, true);
Handle(Geom_TrimmedCurve) aSeg0 = GC_MakeSegment(aPnt0, aPnt1);
Handle(Geom_TrimmedCurve) aSeg1 = GC_MakeSegment(aPnt2, aPnt0);
// Wire
TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(aSeg0);
TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(aArc);
TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(aSeg1);
TopoDS_Wire aWire  = BRepBuilderAPI_MakeWire(anEdge1, anEdge2, anEdge3);
// Surface
GC_MakeConicalSurface coneMaker(gp_Ax2(aPnt0, aDir, gp_Dir(1.0, 0.0, 0.0)), a, 0.0);
Handle(Geom_ConicalSurface) aCone = coneMaker.Value();
// Face
BRep_Builder B;
B.MakeFace(m_Shape, aCone, 0.001);
BRepLib_MakeFace faceMaker(m_Shape);
faceMaker.Add(aWire);
m_Shape = faceMaker.Face();

Result of rendering this m_Shape shown in the first attached screenshot.

Adding

Handle(ShapeFix_Face) aFixShape = new ShapeFix_Face(m_Shape);
if (aFixShape->Perform())
{
    m_Shape = aFixShape->Face();
}

does not help much. See the second screenshot.

What am I doing wrong?

P.S. Green lines with arrows are just my visualization of the edges.

Dmitrii Pasukhin's picture

Hello, the topology is not valid. The wire need to organise circle and also you need to add 2d curve (pcurve, 2d curve, seam edge).

The most comfortable example with demo: https://dev.opencascade.org/content/sample-cylinder-order-edges-wire

Related ticket: https://dev.opencascade.org/content/creating-face-cylindrical-surface

Working sample: https://dev.opencascade.org/content/splitting-edge-cylinder

My overall recommendation - try to work with OCCT's Draw command and play with topology and geometry to get the understanding of the topology.

Best regards, Dmitrii.

Ivan Poberezhnyk's picture

Thanks for the quick reply. My wire does form a circle: line (p0, p1), an arc (p1, p2), and the second line (p2, p0). As for the pcurves - my bad, it is not my real code, just a code snippet where I'm trying to understand issues I have with cones. I modified the code to add pcurves to each edge using projection (should be enough for the POC), like this:

ShapeAnalysis_Edge sae;
Handle(ShapeConstruct_ProjectCurveOnSurface) project = new ShapeConstruct_ProjectCurveOnSurface;
project->SetPrecision(tolerance);
project->Init(aCone, tolerance);
{
    TopoDS_Vertex V1 = sae.FirstVertex(anEdge1);
    TopoDS_Vertex V2 = sae.LastVertex(anEdge1);
    B.UpdateVertex(V1, tolerance);
    B.UpdateVertex(V2, tolerance);
    Handle(Geom2d_Curve) c2d;
    project->Perform(aSeg0, aSeg0->FirstParameter(), aSeg0->LastParameter(), c2d);
    B.UpdateEdge(anEdge1, c2d, aCone, TopLoc_Location(), tolerance);
}

And the same for the two other edges. I have also set the wire orientation to TopAbs_REVERSED. Now the code is rendered, and it shows the same issue I have in my main code - the pure quality of the cone, shown in the screenshots.