# OpenCASCADE Conic to BSpline Curves-Parabola

#### OpenCASCADE Conic to BSpline Curves-Parabola

eryar@163.com

Abstract. Rational Bezier Curve can represent conic curves such as circle, ellipse, hyperbola, .etc. But how to convert a conic curve to BSpline curve is still question, i.e. Represent a conic curve in BSpline form. Parabola curve is the most simple conic curve, that the parabola does not require rational functions. Let’s begin from the simplest one…

Key Words. OpenCASCADE, Convert, Parabola, BSplineCurve, Conic Curve

1. Introduction

Figure 1.1 Parabola Fuction

2. Parametric Representations

3. Conversion Algorithm

v K=0；       表示退化的二次曲线：一对直线段P0P1和P1P2；

v K∈[0，1]；  表示双曲线；

v K=1；       表示抛物线；

v K∈[1, +∞]； 表示椭圆；

v K=+∞；     表示连接P0和P2的直线段；

Figure 3.1 不同的权因子ω1 定义的圆锥截线

P1点可以由二次有理Bezier曲线的公式列方程计算得出，但这并不是一个方便的方法。一种更方便的方法是：在这条曲线上指定第三个点，该点对应于某个特定的参数，例如u=1/2。点S＝C(1/2)称为圆锥截线的肩点(shoulder point)，如图3.1所示。将u=1/2代入二次有理Bezier公式得：

4. Code Analysis

```//=======================================================================
//function : Convert_ParabolaToBSplineCurve
//purpose  :
//=======================================================================
Convert_ParabolaToBSplineCurve::Convert_ParabolaToBSplineCurve
(const gp_Parab2d&   Prb,
const Standard_Real U1 ,
const Standard_Real U2  )
: Convert_ConicToBSplineCurve (MaxNbPoles, MaxNbKnots, TheDegree)
{
Standard_DomainError_Raise_if( Abs(U2 - U1) < Epsilon(0.),
\"Convert_ParabolaToBSplineCurve\");

Standard_Real UF = Min (U1, U2);
Standard_Real UL = Max( U1, U2);
Standard_Real p = Prb.Parameter();

nbPoles = 3;
nbKnots = 2;
isperiodic = Standard_False;
knots->ChangeArray1()(1) = UF;  mults->ChangeArray1()(1) = 3;
knots->ChangeArray1()(2) = UL;  mults->ChangeArray1()(2) = 3;

weights->ChangeArray1()(1) = 1.;
weights->ChangeArray1()(2) = 1.;
weights->ChangeArray1()(3) = 1.;

gp_Dir2d Ox = Prb.Axis().XDirection();
gp_Dir2d Oy = Prb.Axis().YDirection();
Standard_Real S = ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.) ?  1 : -1;

// poles expressed in the reference mark
poles->ChangeArray1()(1) =
gp_Pnt2d( ( UF * UF) / ( 2. * p), S *   UF            );
poles->ChangeArray1()(2) =
gp_Pnt2d( ( UF * UL) / ( 2. * p), S * ( UF + UL) / 2. );
poles->ChangeArray1()(3) =
gp_Pnt2d( ( UL * UL) / ( 2. * p), S *   UL            );

// replace the bspline in the mark of the parabola
gp_Trsf2d Trsf;
Trsf.SetTransformation( Prb.Axis().XAxis(), gp::OX2d());
poles->ChangeArray1()(1).Transform( Trsf);
poles->ChangeArray1()(2).Transform( Trsf);
poles->ChangeArray1()(3).Transform( Trsf);
}```

```/*
*
*        File    : Main.cpp
*        Author  : eryar@163.com
*        Date    : 2014-10-02 20:46
*        Version : 1.0v
*
*    Description : OpenCASCADE conic to BSpline curve-Parabola.
*
*      Key words : OpenCascade, Parabola, BSpline Curve, Convert
*/

#define HAVE_CONFIG_H

#include <gp_Parab2d.hxx>

#include <Convert_ParabolaToBSplineCurve.hxx>

void DumpConvertorInfo(const Convert_ConicToBSplineCurve &theConvertor)
{
Standard_Integer aCounter = 0;

std::cout << \"Convert Result\" << std::endl;
std::cout << \"Degree: \" << theConvertor.Degree() << std::endl;
std::cout << \"Periodic: \" << (theConvertor.IsPeriodic() ? \"yes\" : \"no\") << std::endl;

std::cout << \"Knots: \" << std::endl;
for (Standard_Integer i = 1;i <= theConvertor.NbKnots(); ++i)
{
for (Standard_Integer j = 1; j <= theConvertor.Multiplicity(i); ++j)
{
std::cout << ++aCounter << \": \" << theConvertor.Knot(i) << std::endl;
}
}

std::cout << \"Poles(Weight): \" << std::endl;
for (Standard_Integer i = 1; i <= theConvertor.NbPoles(); ++i)
{
gp_Pnt2d aPole = theConvertor.Pole(i);

std::cout << i << \": \" << aPole.X() << \", \" << aPole.Y()
<< \" W(\" << theConvertor.Weight(i) << \")\" << std::endl;
}
}

void TestParabolaConversion(void)
{
gp_Parab2d aParabola(gp::OX2d(), 1.0);

Convert_ParabolaToBSplineCurve aConvertor(aParabola, 1.0, M_PI);

DumpConvertorInfo(aConvertor);
}

int main(int argc, char **argv)
{
TestParabolaConversion();

return 0;
}```

Figure 4.1 Convert Parabola to BSpline Curve Result

5. Conclusion

NURBS的一个优势就是统一了曲线曲面的表示方法，即不仅可以表示自由曲线曲面，还可精确表示圆锥曲线曲面。其中抛物线是最简单的圆锥截线，从简单的抛物线转换成NURBS曲线着手，学习NURBS是如何来表示圆锥截线的。

Figure 5.1 Set Library Path and Add Libraries in Codelite

# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# ldconfig

Figure 5.2 Use lld command to check depends

6. References

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

2. 赵罡，穆国旺，王拉柱译. 非均匀有理B样条. 清华大学出版社. 2010

3. 王仁宏，李崇君，朱春钢. 计算几何教程. 科学出版社. 2008