Geom2dGcc_Circ2d2TanRad

I tried to draw 2d fillet.
I have to lines which intersect with each other.
I want to have fillet radius instead of corner.
How can I do it using Geom2dGcc_Circ2d2TanRad?

Maybe somebody can write simple example?

Thank you in advance.
Pawel.

Pawel's picture

Dear Pawel,

I haven't used that myself. However, you can have a look at the OC source:
\ros\src\ChFi2d\ChFi2d_Builder.cxx
\ros\src\Geom2dGcc\Geom2dGcc_Circ2d2TanRad.cxx

I use BRepFilletAPI_MakeFillet2d. This is a snippet from my code:

///
/// Adds fillets to a wire.
///
/// The input wire.
/// The output wire with fillets.
/// The array list containing:
/// (0) - x coordinate of the vertex to add the fillet to;
/// (1) - z coordinate of the vertex to add the fillet to;
/// (2) - the radius of the fillet.
/// The input wire is situated in the XZ plane.
/// true if the method succeeds.
/// Otherwise false.
bool shellDocBase::AddFilletsToPlanarWire(
BRepBuilderAPI_MakeWire &wire, BRepBuilderAPI_MakeWire &outputWire,
ArrayList ^ filletsArrayList)
{
if(filletsArrayList == nullptr)
{
TraceWarning("shellDocBase Error. AddFilletsToPlanarWire - ArrayList NULL pointer.");
return false;
}

BRepFilletAPI_MakeFillet2d fillet;
fillet.Init(BRepBuilderAPI_MakeFace(wire.Wire()));

BRepTools_WireExplorer Ex;
TopoDS_Edge firstEdge;
TopoDS_Edge secondEdge;
TopoDS_Vertex vertex;
gp_Pnt point;
gp_Pnt actPoint;
int j = 1;
bool first = true;

int nb = -1;
TopTools_IndexedMapOfShape aMap1;
TopExp::MapShapes(wire, TopAbs_EDGE, aMap1);
nb = aMap1.Extent();

for(Ex.Init(wire); Ex.More(); ) //iterate through edges
{
if(first == true)
{
firstEdge = Ex.Current();
first = false;
}

Ex.Next();

//if the number of edges is odd don't proceed
if(Ex.More() == Standard_False)
break;

secondEdge = Ex.Current();

//get the common vertex of the two edges
TopExp::CommonVertex(firstEdge, secondEdge, vertex);

point = BRep_Tool::Pnt(vertex);

//check if at this edge there is a fillet
for(j = 0; jCount; )
{
actPoint.SetX(System::Double::Parse(filletsArrayList->default[j + 0]->ToString()));
actPoint.SetY(0);
actPoint.SetZ(System::Double::Parse(filletsArrayList->default[j + 1]->ToString()));

if(actPoint.IsEqual(point, Precision::Confusion()) == Standard_True)
{
TraceDebug(" shellDocBase: AddFilletsToPlanarWire - adding fillet.");
fillet.AddFillet(vertex, System::Double::Parse(filletsArrayList->default[j + 2]->ToString()));
break;
}

j +=3;
}

firstEdge = secondEdge;
}

if(fillet.Status() != ChFi2d_IsDone)
{
CString message = "";

switch(fillet.Status())
{
case ChFi2d_NotPlanar:
message = "ChFi2d_NotPlanar";
break;
case ChFi2d_NoFace:
message = "ChFi2d_NoFace";
break;
case ChFi2d_InitialisationError:
message = "ChFi2d_InitialisationError";
break;
case ChFi2d_ParametersError:
message = "ChFi2d_ParametersError";
break;
case ChFi2d_Ready:
message = "ChFi2d_Ready";
break;
case ChFi2d_IsDone:
message = "ChFi2d_IsDone";
break;
case ChFi2d_ComputationError:
message = "ChFi2d_ComputationError";
break;
case ChFi2d_ConnexionError:
message = "ChFi2d_ConnexionError";
break;
case ChFi2d_TangencyError:
message = "ChFi2d_TangencyError";
break;
case ChFi2d_FirstEdgeDegenerated:
message = "ChFi2d_FirstEdgeDegenerated";
break;
case ChFi2d_LastEdgeDegenerated:
message = "ChFi2d_LastEdgeDegenerated";
break;
case ChFi2d_BothEdgesDegenerated:
message = "ChFi2d_BothEdgesDegenerated";
break;
case ChFi2d_NotAuthorized:
message = "ChFi2d_NotAuthorized";
break;
default:
message = "Unknown";
break;
}

TraceError(" shellDocBase Error. AddFilletsToPlanarWire - Fillet status - not done: " + gcnew String(message) + ".");
return false;
}

if(fillet.Shape().IsNull() == Standard_True)
{
TraceError(" shellDocBase Error. AddFilletsToPlanarWire - Fillet shape Null.");
return false;
}

//=====================================
TraceDebug(" shellDocBase: AddFilletsToPlanarWire - consulting fillet result.");
BRepBuilderAPI_MakeWire newWire;
TopTools_IndexedMapOfShape aMap;

TopExp::MapShapes(fillet.Shape(), TopAbs_WIRE, aMap);
if(aMap.Extent() != 1)
{
TraceErrorFormattedStr(" shellDocBase Error. AddFilletsToPlanarWire - multiple/no wires detected: ","%i",".",aMap.Extent());
return false;
}

//add edges to the wire
Ex.Clear();
for(Ex.Init(TopoDS::Wire(aMap(1))); Ex.More(); Ex.Next())
{
newWire.Add(Ex.Current());
}
outputWire = newWire;

return true;
}

Hope it helps.

Good luck!
Pawel

Pawel Dobrowolski's picture

Dear Pawel,

I finally managed to do fillet using Geom2dGcc_Circ2d2TanRad:

I do it in following way. Maybe it isn't optimal solution, but for my purposes seems simpler.

gp_Lin2d line_angle, line_bottom; //defined as program needs

Handle(Geom2d_Curve) line_angle_gc;
Handle(Geom2d_Curve) line_bottom_gc;

Handle(Geom2d_Line) line_angle_2d;
Handle(Geom2d_Line) line_bottom_2d;

Geom2d_Line line_bot = Geom2d_Line(line_bottom);
Geom2d_Line line_ang = Geom2d_Line(line_angle);

line_angle_2d = &line_ang;
line_bottom_2d = &line_bot;

line_angle_gc = Handle (Geom2d_Line)::DownCast(line_angle_2d);
line_bottom_gc = Handle (Geom2d_Line)::DownCast(line_bottom_2d);

Geom2dAdaptor_Curve Curve1 ( line_bottom_gc) ;
Geom2dAdaptor_Curve Curve2 ( line_angle_gc) ;

Geom2dGcc_QualifiedCurve QCurve1 ( Curve1, GccEnt_unqualified );
Geom2dGcc_QualifiedCurve QCurve2 ( Curve2, GccEnt_unqualified);

//fillet is Standard_Real
class Geom2dGcc_Circ2d2TanRad* bottom_circle_constructor = new Geom2dGcc_Circ2d2TanRad(QCurve1, QCurve2, fillet, 1.0e-6);

gp_Circ2d bottom_circle = bottom_circle_constructor->ThisSolution(1);

Standard_Real parsol, pararg;

gp_Pnt2d intersection2d_3;
gp_Pnt2d intersection2d_4;
bottom_circle_constructor->Tangency1(1,parsol,pararg,intersection2d_3);
bottom_circle_constructor->Tangency2(1,parsol,pararg,intersection2d_4);

delete bottom_circle_constructor;

//define plane XY
gp_Ax2 Axis = gp_Ax2 (gp_Pnt( 0., 0., 0.),gp_Dir( 0., 0., 1.));

Geom_Plane plane_XY = Geom_Plane(gp_Ax3(Axis));

Handle(Geom_Plane) plane_XY_h;
Handle(Geom_Surface) surface_XY;

//surface from plane
plane_XY_h = &plane_XY;
surface_XY = Handle_Geom_Surface::DownCast(plane_XY_h);

gp_Pnt intersection_3(intersection2d_3.X(), intersection2d_3.Y(), 0);
gp_Pnt intersection_4(intersection2d_4.X(), intersection2d_4.Y(), 0);

Handle(Geom2d_TrimmedCurve) bottom_arc = GCE2d_MakeArcOfCircle(bottom_circle, intersection2d_3, intersection2d_4);

TopoDS_Edge aEdge2 = BRepBuilderAPI_MakeEdge(bottom_arc,surface_XY);

//now I can add arc to any wire
TopoDS_Wire aWire2 = BRepBuilderAPI_MakeWire(aWire1, aEdge2);

//-------

I receive aEdge2 which arc of circle, with end points
intersection_3, intersection_4.

The main problem is many conversions of types.

Regards,
Pawel D.

akshay gaikwad's picture

hi pawel,

can you tell me, how to give fillet to one horizontal line and one angled line, which both are attach together.