How to convert a trimmedCurve on an arc of circle

Hi,

I've selected an edge (TopoDS_Edge) on the screen witch is in reality an arc of a circle.

How can I convert this edge to obtain the circle arc informations (gp_Pnt, Radius...).

Thank you in advance for your answer.

Stephane Routelous's picture

BRepAdaptor_Curve bac(theEdge);
GeomAbs_CurveType theCurveType = bac.GetType();
if ( theCurveType == GeomAbs_Circle )
{
gp_Circ theCircle = bac.Circle();
Standard_Real r = theCircle.Radius();
}

should work

HTH,

Stephane

Kreshnik's picture

Thank you very much Stephane it works,

Kreshnik HASANI

Kreshnik's picture

Hi,

This method works on imported step files witch contents a CIRCLE element. I'm importing a step file which has no CIRCLE element in its step description. However in the screen I can see circles. When I try to get these circles with this method it doesn't work. The edge is not a GeomAbs_Circle.

How can I get these circles ?

Thanks for your response.

Kreshnik HASANI

Kreshnik's picture

I finally found the solution.

The arc is if fact in this case a BSpline curve. So I have to convert it in a circle to get its radius.

I use tis code :

// Conversion du format de l'arrete
BRepAdaptor_Curve bac(myEdge);
GeomAbs_CurveType theCurveType = bac.GetType();

if (theCurveType == GeomAbs_Circle)
{
// Obtention du rayon de l'arc de cercle
gp_Circ theCircle = bac.Circle();
radius = theCircle.Radius();
str_col = TCollection_AsciiString(radius);
Message = str_col;
}else if((theCurveType != GeomAbs_Line) && (theCurveType != GeomAbs_Ellipse) && (theCurveType != GeomAbs_Hyperbola) && (theCurveType != GeomAbs_Parabola) && (theCurveType != GeomAbs_BezierCurve) && (theCurveType != GeomAbs_OtherCurve))
{

// Obtention des deux extremités
Standard_Real First,Last;
Handle(Geom_Curve) myCurve = BRep_Tool::Curve(myEdge, First, Last);
Handle(Geom_TrimmedCurve) myTrimmed = new Geom_TrimmedCurve(myCurve, First, Last);
gp_Pnt pt_start = myTrimmed->StartPoint();
gp_Pnt pt_end = myTrimmed->EndPoint();

// Conversion en BSplineCurve
Handle(Geom_BSplineCurve) myBSplCurve = GeomConvert::CurveToBSplineCurve(myTrimmed);

// Récuperation de deux pôles
Standard_Integer nb_poles = myBSplCurve->NbPoles();
gp_Pnt pt_pole1 = myBSplCurve->Pole(2);
gp_Pnt pt_pole2 = myBSplCurve->Pole(nb_poles-1);

// On projette les pôles sur la courbe
GeomAPI_ProjectPointOnCurve proj1;
GeomAPI_ProjectPointOnCurve proj2;
proj1.Init(pt_pole1, myCurve, First, Last);
proj2.Init(pt_pole2, myCurve, First, Last);

// On recupere les points de projection
gp_Pnt pt_curve1 = proj1.NearestPoint();
gp_Pnt pt_curve2 = proj2.NearestPoint();

// On crée deux cercles et on recupere les rayons respectifs
gce_MakeCirc gce_circ1 = gce_MakeCirc(pt_start,pt_end,pt_curve1);
gp_Circ circle1 = gce_circ1.Value();
Standard_Real radius1 = circle1.Radius();
gce_MakeCirc gce_circ2 = gce_MakeCirc(pt_start,pt_end,pt_curve2);
gp_Circ circle2 = gce_circ2.Value();
Standard_Real radius2 = circle2.Radius();

// On teste que les cercles soient bien crées et egaux
if ((gce_circ1.Status() == gce_Done) && (gce_circ2.Status() == gce_Done) && (fabs(radius2-radius1) < 0.01))
{
// On recupere et returne le rayon
radius = (radius1 + radius2) / 2;
radius = radius * 2;
str_col = TCollection_AsciiString(radius);
Message = str_col;

}else{Message = "Error : The selected edge is not a circle or an arc of circle";}

Sorry for the french comments !!

Kreshnik HASANI