# Intersection between 2d conic in OpenCASCADE

### Intersection between 2d conic in OpenCASCADE

eryar@163.com

Abstract. OpenCASCADE provides the algorithm to implement of the intersection between two 2d conic curve. The conic is defined by its implicit quadaratic equation, so the intersection problem is become a polynomial roots finding problem. The paper focus on the two conic curve intersection algorithm implementation.

Key Words. 2d conic intersection, conic equation,

1.Introduction

Figure 1. 圆锥曲线相交

2.Conic Implicit Equation

IntAna2d_Conic::IntAna2d_Conic (const gp_Lin2d& L) {

a = 0.0;
b = 0.0;
c = 0.0;
L.Coefficients(d,e,f);
f = 2*f;
}

IntAna2d_Conic::IntAna2d_Conic (const gp_Circ2d& C) {

C.Coefficients(a,b,c,d,e,f);
}

IntAna2d_Conic::IntAna2d_Conic (const gp_Elips2d& E) {

E.Coefficients(a,b,c,d,e,f);
}

IntAna2d_Conic::IntAna2d_Conic (const gp_Parab2d& P) {
P.Coefficients(a,b,c,d,e,f);
}

IntAna2d_Conic::IntAna2d_Conic (const gp_Hypr2d& H) {
H.Coefficients(a,b,c,d,e,f);
}

3.Intersection between Circle and Conic

void IntAna2d_AnaIntersection::Perform(const gp_Circ2d& Circle,
const IntAna2d_Conic& Conic)
{
Standard_Boolean CIsDirect = Circle.IsDirect();
Standard_Real A,B,C,D,E,F;
Standard_Real pcc,pss,p2sc,pc,ps,pcte;
Standard_Integer i;
Standard_Real tx,ty,S;

done = Standard_False;
nbp  = 0;
para = Standard_False;
empt = Standard_False;
iden = Standard_False;

gp_Ax2d Axe_rep(Circle.XAxis());

Conic.Coefficients(A,B,C,D,E,F);
Conic.NewCoefficients(A,B,C,D,E,F,Axe_rep);

pcc = A*radius_P2 - pss;                            // COS ^2
p2sc =C*radius_P2;                                  // 2 SIN COS
pcte= F + pss;                                      // 1

math_TrigonometricFunctionRoots Sol(pcc,p2sc,pc,ps,pcte,0.0,2.0*M_PI);

if(!Sol.IsDone()) {
cout << \"\\n\\nmath_TrigonometricFunctionRoots -> NotDone\\n\\n\"<<endl;
done=Standard_False;
return;
}
else {
if(Sol.InfiniteRoots()) {
iden=Standard_True;
done=Standard_True;
return;
}
nbp=Sol.NbSolutions();
for(i=1;i<=nbp;i++) {
S = Sol.Value(i);
Coord_Ancien_Repere(tx,ty,Axe_rep);
if(!CIsDirect)
S = M_PI+M_PI-S;
lpnt[i-1].SetValue(tx,ty,S);
}
Traitement_Points_Confondus(nbp,lpnt);
}
done=Standard_True;
}

Figure 2. 圆及其参数方程

4.Intersection between Ellipse and Conic

void IntAna2d_AnaIntersection::Perform(const gp_Elips2d& Elips,
const IntAna2d_Conic& Conic)
{
Standard_Boolean EIsDirect = Elips.IsDirect();
Standard_Real A,B,C,D,E,F;
Standard_Real pcte,ps,pc,p2sc,pcc,pss;
Standard_Integer i;
Standard_Real tx,ty,S;

done = Standard_False;
nbp = 0;
para = Standard_False;
iden = Standard_False;
empt = Standard_False;

gp_Ax2d Axe_rep(Elips.XAxis());

Conic.Coefficients(A,B,C,D,E,F);
Conic.NewCoefficients(A,B,C,D,E,F,Axe_rep);

pcte=F+pss;                                         // 1

math_TrigonometricFunctionRoots Sol(pcc,p2sc,pc,ps,pcte,0.0,2.0*M_PI);

if (!Sol.IsDone()) {
done=Standard_False;
return;
}
else {
if(Sol.InfiniteRoots()) {
iden=Standard_True;
done=Standard_True;
return;
}
nbp=Sol.NbSolutions();
for(i=1;i<=nbp;i++) {
S = Sol.Value(i);
Coord_Ancien_Repere(tx,ty,Axe_rep);
if(!EIsDirect)
S = M_PI+M_PI-S;
lpnt[i-1].SetValue(tx,ty,S);
}
Traitement_Points_Confondus(nbp,lpnt);
}
done = Standard_True;
}

5.Intersection between Parabola and Conic

void IntAna2d_AnaIntersection::Perform(const gp_Parab2d& P,
const IntAna2d_Conic& Conic)
{
Standard_Boolean PIsDirect = P.IsDirect();
Standard_Real A,B,C,D,E,F;
Standard_Real px4,px3,px2,px1,px0;
Standard_Integer i;
Standard_Real tx,ty,S;
Standard_Real un_sur_2p=0.5/(P.Parameter());
gp_Ax2d Axe_rep(P.MirrorAxis());

done = Standard_False;
nbp = 0;
para = Standard_False;
empt = Standard_False;
iden = Standard_False;

Conic.Coefficients(A,B,C,D,E,F);
Conic.NewCoefficients(A,B,C,D,E,F,Axe_rep);

//-------- \'Parametre\'  y avec y=y  x=y^2/(2 p)

px0=F;
px1=E+E;
px2=B + un_sur_2p*(D+D);
px3=(C+C)*un_sur_2p;
px4=A*(un_sur_2p*un_sur_2p);

MyDirectPolynomialRoots Sol(px4,px3,px2,px1,px0);

if(!Sol.IsDone()) {
done=Standard_False;
}
else {
if(Sol.InfiniteRoots()) {
iden=Standard_True;
done=Standard_True;
}
nbp=Sol.NbSolutions();
for(i=1;i<=nbp;i++) {
S = Sol.Value(i);
tx=un_sur_2p*S*S;
ty=S;
Coord_Ancien_Repere(tx,ty,Axe_rep);
if(!PIsDirect)
S =-S;
lpnt[i-1].SetValue(tx,ty,S);
}
Traitement_Points_Confondus(nbp,lpnt);
}
done=Standard_True;
}

6.Conclusion

7.References

1. 人民教育出版社中学数学室. 数学第二册上. 人民教育出版社. 2000

2. 同济大学数学教研室. 高等数学. 高等教育出版社. 1996

3. 易大义, 沈云宝, 李有法. 计算方法. 浙江大学出版社. 2002

4. 李原, 张开富, 余剑峰. 计算机辅助几何设计技术及应用. 西北工业大学出版社. 2007

5. 丘维声. 解析几何. 北京大学出版社. 1996