Creating a Fillet

To create a fillet in a sketch you must first have two sketch lines.

Then you can call the create_fillet function

create_fillet(spCurve1,spCurve2,10,sketch2DFactory,spSketch);
create_fillet(spCurve2,spCurve3,10,sketch2DFactory,spSketch);
create_fillet(spCurve3,spCurve4,10,sketch2DFactory,spSketch);
create_fillet(spCurve4,spCurve1,10,sketch2DFactory,spSketch);

The first two parameters passed in are the two coincident curves you want to form a fillet on. The second parameter is the desired fillet radius. The third parameter is the Sketch Factory that is used to create sketch geometry. The last parameter is the sketch identifier.

The create_fillet code is shown below

CATI2DCurve_var create_fillet(CATI2DCurve_var curve1,CATI2DCurve_var curve2, double radius,CATI2DWFFactory_var sketch2DFactory,CATISketch_var &spSketch){
CATI2DConstraintFactory_var spConstraint2DFactory(spSketch);
CATI2DCurve_var fillet;
double end_pnt1[2],start_pnt1[2],end_pnt2[2],start_pnt2[2];
double pt_center[2];//  = {70., 40.};
//                   Asks the end points of each curve
CATI2DPoint_var curve1_end = curve1->GetEndPoint();
curve1_end->GetPointData(end_pnt1);
CATI2DPoint_var curve1_start = curve1->GetStartPoint();
curve1_start->GetPointData(start_pnt1);
CATI2DPoint_var curve2_end = curve2->GetEndPoint();
curve2_end->GetPointData(end_pnt2);
CATI2DPoint_var curve2_start = curve2->GetStartPoint();
curve2_start->GetPointData(start_pnt2);
//                   Finds the vectors of each curve
CATMathPoint2D sp1(start_pnt1);
CATMathPoint2D ep1(end_pnt1);
CATMathVector2D vec1 = sp1 - ep1;
vec1.Normalize();
CATMathPoint2D sp2(start_pnt2);
CATMathPoint2D ep2(end_pnt2);
CATMathVector2D vec2 = sp2 - ep2;
vec2.Normalize(); 
//                   Gets the angle between both curves
CATAngle ang1=vec1.GetAngleTo(vec2);
double length=fabs(radius/tan(ang1/2));
double side_pnt[2];
//                   Checks to see which ends are coincident
if(fabs(end_pnt1[0]-end_pnt2[0])<.0001 && fabs(end_pnt1[1]-end_pnt2[1])<.0001){
side_pnt[0]=end_pnt1[0]+vec1.GetX()*length;
side_pnt[1]=end_pnt1[1]+vec1.GetY()*length;
pt_center[0]=side_pnt[0]+vec2.GetX()*radius;
pt_center[1]=side_pnt[1]+vec2.GetY()*radius;
}else if(fabs(start_pnt1[0]-end_pnt2[0])<.0001 && fabs(start_pnt1[1]-end_pnt2[1])<.0001){
side_pnt[0]=end_pnt1[0]-vec1.GetX()*length;
side_pnt[1]=end_pnt1[1]-vec1.GetY()*length;
pt_center[0]=side_pnt[0]+vec2.GetX()*radius;
pt_center[1]=side_pnt[1]+vec2.GetY()*radius;
}else if(fabs(start_pnt1[0]-start_pnt2[0])<.0001 && fabs(start_pnt1[1]-start_pnt2[1])<.0001){
side_pnt[0]=end_pnt1[0]-vec1.GetX()*length;
side_pnt[1]=end_pnt1[1]-vec1.GetY()*length;
pt_center[0]=side_pnt[0]-vec2.GetX()*radius;
pt_center[1]=side_pnt[1]-vec2.GetY()*radius;
}else if(fabs(end_pnt1[0]-start_pnt2[0])<.0001 && fabs(end_pnt1[1]-start_pnt2[1])<.0001){
side_pnt[0]=end_pnt1[0]+vec1.GetX()*length;
side_pnt[1]=end_pnt1[1]+vec1.GetY()*length;
pt_center[0]=side_pnt[0]-vec2.GetX()*radius;
pt_center[1]=side_pnt[1]-vec2.GetY()*radius;
}else{
printf("Your curves are not coincident\n");
}	
//             Create the fillet and constrain it to be tangent to both curves	
fillet = sketch2DFactory->CreateCorner(curve1, curve2, pt_center, &radius);
CATI2DTopologicalOperators_var spOperateur = spSketch;
spOperateur->InsertCorner(fillet,curve1,1,curve2,1);
spConstraint2DFactory->CreateConstraint( curve1, NULL, fillet, NULL, NULL, NULL, NULL, Cst2DType_Tangent, 0, 0);
spConstraint2DFactory->CreateConstraint( fillet, NULL, curve2, NULL, NULL, NULL, NULL, Cst2DType_Tangent, 0, 0);
spConstraint2DFactory->CreateConstraint( fillet, NULL, NULL, NULL, NULL, NULL, NULL, Cst2DType_Radius, 0, 1);//*/
return fillet;
}

NOTE: Be sure to close the sketch when are done using it

spSketch->CloseEdition();