# To find intersection point of a self-intersecting B-Spline curve

Which set of functions should be used?

I am using the Geom_OffsetCurve function to find the offset of a b-spline curve. The problem is that the obtained b-spline curve is self-intersecting.
So,I want to find the intersection point in order to trim the curve. Can anyone help me plzzz?

Sindhu We have a function
Geom2dAPI_InterCurveCurve (const Handle(Geom2d_Curve)&C1, const Standard_Real Tol=1.0e-6)
for 2d curve. But I need a function for a 2d curve in 3d space.

I cannot find any function like "GeomAPI_InterCurveCurve (const Handle(Geom2d_Curve)&C1, const Standard_Real Tol=1.0e-6)"  Hi,
There is no function like GeomAPI_InterCurveCurve. So the best idea is to convert the curve to 2D then find the intersecting points and trim the curve and then conver to 3d Curve.

Here is the sample Code, I think this will help u.

Consider u r having two 3D curve,

//First step Have a handle for the Curve

Handle(Geom_Curve) Line3dCurve1;
Handle(Geom_Curve) Line3dCurve1;

// Have the Axis

gp_Ax3 theAxe(gp::XOY()); //XOY can be changed according to the axis that you are using

gp_Pln PL(theAxe);

//Converting 3D to 2D Curve

Handle(Geom2d_Curve) Line2dCurve1 = GeomAPI::To2d(Line3dCurve1,PL);
Handle(Geom2d_Curve) Line2dCurve2 = GeomAPI::To2d(Line3dCurve2,Line2dCurve2 ); //Put (Line3dCurve2,Line2dCurve1 ); if u want to find the same intersection Points.

//Finding the Intersection Points
Geom2dAPI_InterCurveCurve Intect1= Geom2dAPI_InterCurveCurve(Line2dCurve1 ,curve);

int totIntPoints = Intect1.NbPoints();

//totIntPoints will return the total no of intersection Point

gp_Pnt2d IntPoint2d = Intect1.Point(1); // Will return first intersection Point. If will return error if no intersection points are present. Similarly Intect1.Point(2) will return 2nd intersection Point if it is present.Intect1.Point(i) will return ith intersection and i value should be equal or less than totIntPoints.
gp_Pnt IntPoint(IntPoint2d.X(),IntPoint2d.Y(),0);

//Then trim the curve with he help of the Points u get.
//Then conver to 3D using

Handle(Geom_Curve) LineCurve3D = GeomAPI::To2d(Line2dCurve1 ,PL);

Regards,
Vidhyan Thanks a lot Vidhyan. I will try the code and ask you the doubts.

I think the last statement for converting to 3D curve has a printing mistake hope it should be
Handle(Geom_Curve) LineCurve3D = GeomAPI::To3d(Line2dCurve1 ,PL); Ya itz typing Mistake it should be,

Handle(Geom_Curve) LineCurve3D = GeomAPI::To3d(Line2dCurve1 ,PL);

Regards,
Vidhyan Hi Vidyan

I tried the process. But, the problem is that for some curves it gives correct number of intersection points and for some curves it gives wrong. Does the function
Handle(Geom2d_Curve) Line2dCurve1 = GeomAPI::To2d(Line3dCurve1 ,PL);
will project the curve on the given plane PL or will it transform the curve to the plane PL.

My code:
TColgp_Array1OfPnt array1 (1,5); // sizing array
array1.SetValue(1,gp_Pnt(-4,0,0)); array1.SetValue(2,gp_Pnt(-7,0,2));
array1.SetValue(3,gp_Pnt(-6,0,3)); array1.SetValue(4,gp_Pnt(-4,0,3));
array1.SetValue(5,gp_Pnt(-3,0,5));
gp_Dir V(0,-1,0);
const Standard_Integer DegMin=3,DegMax=8;
const GeomAbs_Shape Continuity=GeomAbs_C1;
const Standard_Real Tol3D=1.0e-3;
Handle(Geom_BSplineCurve) SPL1= GeomAPI_PointsToBSpline(array1,DegMin,DegMax,Continuity,Tol3D).Curve(); // original curve
Standard_Real dist2 = 2.0;
Handle(Geom_OffsetCurve) OC2 =
new Geom_OffsetCurve(SPL1,dist2,V); // offset curve
gp_Ax3 theAxe(gp::ZOX());
gp_Pln PL(theAxe);
Handle(Geom2d_Curve) Line2dCurve1 = GeomAPI::To2d(OC2,PL);
Geom2dAPI_InterCurveCurve Intect1= Geom2dAPI_InterCurveCurve(Line2dCurve1);
int totIntPoints = Intect1.NbPoints();
cout<<"\nNo. of Points"< Sindhu,

Observation on your code - why do you deal in 3D at all if you know upfront you work in the plane Y=0 ? Work directly with Geom2d_BSplineCurve and Geom2d_OffsetCurve. You better then restore 2D curves into 3D - as this is precise and unambiguous.
Regarding offsetting and self-intersection, I don't know - it's impossible to say without a picture. Are you certain that it must be 7 instead of 3 ?
In the worst case you will need to debug the code and see why 3 is returned. But first display an offset 2D curve for yourself to see.

Hope this helps somehow.
Roman

--- Hi Roman,

I took y=0 because I am not sure if the function GeomAPI::To2d() is projecting the curve or transforming it. So, I took y=0 so that even if it projects the curve the curve does not change.

I can find 7 intersection points on the curve displayed. But the NbPoints returns only 3.

Sindhu Hi Roman,

I took y=0 because I am not sure if the function GeomAPI::To2d() is projecting the curve or transforming it. So, I took y=0 so that even if it projects the curve the curve does not change.

I can find 7 intersection points on the curve displayed. But the NbPoints returns only 3.

Sindhu Hi Roman,

Can I use BRepOffsetAPI_MakeOffset function to offset a wire?
If yes can you please give me a same code of how to offset a wire using this function...
I tried using it but I couldnot clearly understand the parameters passed to this function...

BRepOffsetAPI_MakeOffset (const TopoDS_Wire &Spine, const GeomAbs_JoinType Join=GeomAbs_Arc)
what does the spine mean( Is it any TopoDS_Wire or only a special kind of it)?
what is the GeomAbs_JoinType mean?

I have a TopoDS_Wire W, I want to offset it to a distance 'dist=1.0'. How can I use this function to offset the give wire W to a distance 'dist'? 