# OpenCASCADE Conic to BSpline Curves-Hyperbola

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. The key point of Hyperbola conversion is to calculate the 2nd pole and its weight factor. The paper focus on the hyperbola convert to the BSpline curves.

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

1. Introduction

Figure 1.1 Conic Sections

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 定义的圆锥截线

4. Code Analysis

```//=======================================================================
//function : Convert_HyperbolaToBSplineCurve
//purpose  :
//=======================================================================

Convert_HyperbolaToBSplineCurve::Convert_HyperbolaToBSplineCurve
(const gp_Hypr2d&    H ,
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);

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

// construction of hyperbola in the reference xOy.

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

// poles expressed in the reference mark
// the 2nd pole is at the intersection of 2 tangents to the curve
// at points P(UF), P(UL)
// the weight of this pole is equal to : Cosh((UL-UF)/2)

weights->ChangeArray1()(1) = 1.;
weights->ChangeArray1()(2) = Cosh((UL-UF)/2);
weights->ChangeArray1()(3) = 1.;

Standard_Real delta = Sinh(UL-UF);
Standard_Real x =     R * ( Sinh(UL) - Sinh(UF)) / delta;
Standard_Real y = S * r * ( Cosh(UL) - Cosh(UF)) / delta;
poles->ChangeArray1()(1) = gp_Pnt2d( R * Cosh(UF), S * r * Sinh(UF));
poles->ChangeArray1()(2) = gp_Pnt2d( x, y);
poles->ChangeArray1()(3) = gp_Pnt2d( R * Cosh(UL), S * r * Sinh(UL));

// replace the bspline in the mark of the hyperbola
gp_Trsf2d Trsf;
Trsf.SetTransformation( H.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-06 20:46
*        Version : 1.0v
*
*    Description : OpenCASCADE conic to BSpline curve-Hyperbola.
*
*      Key words : OpenCascade, Hyperbola, BSpline Curve, Convert
*/

#define WNT
#include <gp_Hypr2d.hxx>

#include <Convert_HyperbolaToBSplineCurve.hxx>

#pragma comment(lib, \"TKernel.lib\")
#pragma comment(lib, \"TKMath.lib\")

void DumpConvertorInfo(const Convert_ConicToBSplineCurve &theConvertor)
{
std::cout << \"Degree: \" << theConvertor.Degree() << std::endl;

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

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

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

std::cout << \"==========================================\" << std::endl;
}

void TestHyperbolaConvert(void)
{
gp_Hypr2d aHyperbola;

Convert_HyperbolaToBSplineCurve aConvertor(aHyperbola, 1.0, M_PI);

std::cout << \"Convert Hyperbola to BSpline Curve: \" << std::endl;
DumpConvertorInfo(aConvertor);
}

int main(int argc, char* argv[])
{
TestHyperbolaConvert();

return 0;
}```

Figure 4.1 Convert Hyperbola to BSpline Curve result

5. Conclusion

6. References

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

2. 数学手册编写组. 数学手册. 高等教育出版社. 1979

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

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