For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings


Need to speed up your development?
Have a look at our:

Samples & Tools


Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Create a part of a cone with a wire

Krunoslav Ivesic's picture

Hi everyone,

I'm trying to build a conical surface limited by a wire. However, I only manage to get the full conical surface, as shown in the picture. What I want to get is only a part of a cone, between the red and the blue edge (the smaller part, as these edges divide the cone in two unequal parts). I tried to create a cone with gp_Cone(), as well as with BRepPrimAPI_MakeCone() and then invoke BRepBuilderAPI_MakeFace(cone, wire) with my cone and wire as arguments. The wire consists of the red and blue edge, as well as of a shorter part of a circle connecting them. So far I don't get anything in the GUI if I use gp_cone() as an argument to BRepBuilderAPI_MakeFace(), and with BRepPrimAPI_MakeCone() I only managed to get the full cone, but not the part indicated by the wire. How do I get only the part of the cone that I need. Thanks!

liuhuiwei's picture

The wire should be a closed wire,use ShapeFix_Wire with mode ClosedWireMode to fix the wire

Krunoslav Ivesic's picture

HI liuhuiwei, thanks for your reply. I tried to fix the wire in various ways, but it still doesn't work.

Roman Lygin's picture

Hi Krunoslav,

There are multiple ways to achieve your goal depending on which input parameters you have and which output you need.

For instance, if you confidently know definitions of your pink and cyan lines (i.e. their origins and directions) you could compute start and end angles on your cone (or have start angle = 0 and compute a difference). These will define your U range on your conical surface. If you know an apex vertex (intersection of the pink and cyan lines) and their end vertices you can compute V range. With that you can create:

Handle(Geom_ConicalSurface) aSurf = new Geom_ConicalSurface (...); //here goes an axis placement with XRef aligned with either of the lines.

BRepBuilderAPI_MakeFace aMakeFace (aSurf, 0., deltaU, startV, endV, tol_degen);

TopoDS_Face aFace = aMakeFace.Face();

Other possible ways include creating a ruled surface with BRepFill::Face() from apex vertex and an edge on the semi-circle.

Of course, any other above will create a standalone face not sharing your pink and cyan edges (but only geometrically coincident). If you need topological sharing there can be other ways.

Hope this helps.


Krunoslav Ivesic's picture

Hi Roman, thanks for the explanations. I'm aware that I can construct a section of that cone, however, I need a solution for the general case and the best way to do it would be with wires. I'll still try with a wire for a while before constructing each cone manually.

Roman Lygin's picture

Hi Krunoslav,

What drives your need to have a wire? Is it to retain to connectivity (edge sharing) with the rest of the model or something else ? Is it really a wire or just edges that need to be retained ?

Anyway, if you really need to retain your wire/edges you will still need to compute parameters for a conical surface (axis placement, ref radius, semi angle) and you seem to understand that, right? Then you could just use BRepBuilderAPI_MakeFace constructor accepting a surface and wire. Then you will need to compute p-curves for your edges on this surface. Notes:

- you wire must be closed (and thus have a degenerated edge corresponding to the apex)

- you can compute edges pcurves either yourself (as you know the 3D curves upfront) and incorporate those into the edges (using BRep_Builder) or you can call ShapeFix_Shape (or _Face) on your resulting face. Again, the way you would need to call ShapeFix_* depends on what your final shape really is, e.g. either a cumulative shell (that includes new face) or the face itself.

Hope this helps.


Krunoslav Ivesic's picture

Hi Roman,

Thanks for your reply. The wire is very suitable for my code since I always have edges ready and I can convert them to a wire easily. I used the ShapeFix_Face() and I managed to get a part of the cone, in case the part doesn't contain the apex. Can you, please, instruct me how to create a degenerated edge pertaining to the apex and add to a wire so that I can also draw cones containing the apex?

Roman Lygin's picture

TopoDS_Vertex V = BRepBuilderAPI_MakeVertex (gp_Pnt (x, y, z)).Vertex() ;
TopoDS_Edge E;
BRep_Builder aBuilder;
aBuilder.MakeEdge (E);
aBuilder.Add (E, V.Oriented (TopAbs_FORWARD));
aBuilder.Add (E, V.Oriented (TopAbs_REVERSED));
//precompute p-curve
Handle(Geom2d_Curve) aCurve = Geom2d_Line (....);
aBuilder.UpdateEdge (E, aCurve, aSurface);
aBuilder.Add (W, E);

If you cannot confidently precompute the p-curve then don't add this degenerated edge and trust ShapeFix to do the job. It should succeed in 99%+ cases.

Krunoslav Ivesic's picture

Hi Roman,

Thank you for your reply. I have already tried with ShapeFix, but it doesn't work if the portion of the cone that I need do draw contains the apex. So, I tried this code snippet and I ran into problems. Can you explain the following, please:

  1. What point do I specify in line 1 (x, y, z)? Cone apex or?
  2. How do I construct a 2D line, i.e., what arguments should I use? I now everything about my cone in 3D, but I don't know where I need to put this degenerate edge.
  3. How do I convert a curve with this Handle? Would this be OK?
    Handle(Geom2d_Curve) aCurve = Handle(Geom2d_Curve)::DownCast(Geom2d_Line(gp_Pnt2d(x_pnt, y_pnt), gp_Dir2d(x_dir, y_dir)).Copy());
  4. Is W here a wire or?

Thank you once again. Sorry for many questions, I'm completely new to OCC.

Roman Lygin's picture

Hi Krunoslav,

1. Yes. That was the answer related to your prior question related to the degenerated edge, and the degenerated edge corresponds to the cone apex.

2. If you know everything about your cone then you obviously have its parametric definition S(u,v). So just compute the p-curve corresponding to your apex. This is v-isoline (i.e. v is const), with v = - R / sin(semi_angle) if you ensure you work with the lower half-cone. u_min and u_max corresponds to your min and max angle respectively.

3. Nope. It's just Handle(Geom_Curve) aLine = new Geom2d_Line (...);

4. Yep.

Well, if you are really new to OCC then I would still recommend using BRepBuilderAPI_MakeFace as given in my first email, at least to process all the cases. Bottom up creation and ShapeFix is rather something for brown belts ;-)

You had mentioned you needed to use the wire (or edges?) but did not provide the rationale. Perhaps that is the complication you unnecessarily impose on yourself without a good reason ;-).

Good luck anyway!


Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.