HOW TO MAKE gp_Cylinder from TopoDS_Shape??

I have made cylinder by
BRepPrimAPI_MakeCylinder MKCyl(cyl_r[i], dist(cyl_v[i][0], cyl_v[i][1]));
TopoDS_Shape cyl = MKCyl.Shape();

Now i need to compute distance between a point and this cylinder.
I have this function:
double CylDist(const gp_Cylinder& cyl, const gp_Pnt& pnt)
double u, v;
ElSLib::Parameters(cyl, pnt, u, v);
return pnt.Distance(ElSLib::Value(u, v, cyl));
But if i want to use this,I need to make gp_Cylinder object.How can i do this?

Fabian Hachenberg's picture

that should work

TopoDS_Face face = TopoDS::Face(cyl)
Handle(Geom_Surface) surface = BRep_Tool::Surface(face);
Handle(Geom_Cylindrical_Surface) cylsurf = Handle(Geom_Cylindrical_Surface)::DownCast(surface);
gp_Cylinder gpcyl = cylsurf->Cylinder();

Gigoga's picture

Sorry but it doesnt work,leading to an exception on the line
TopoDS_Face face=TopoDS::Face(cyl); :

inline TopoDS_Face& TopoDS::Face(TopoDS_Shape& S)
return *(TopoDS_Face*) &S;

Forum supervisor's picture

Hi Giorgii,
It means that your shape is not a face (TypeMismatch...).
You should clear understand with which type of topological
entity you are working (ordinary cylinder has at least 3 faces).
You can't cast for example solid to face. You may use or TopExp_Explorer
or another method like MKCyl.Face() (see BRepPrimAPI_MakeOneAxis class)
if you need a lateral face for example.

Gigoga's picture

Thank you!