Opencascade conic to bspline curves-parabola

[Email protected]

**Abstract.**Rational bezr 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**

Conic and circle are widely used in CAD/CAM. There is no doubt that one of the biggest advantages of a green chart is that it can accurately represent both the conical cut line and the circle and the Free Curve and surface. This advantage is convenient programming, so that all curves can be expressed in a unified data structure. A rational method can be used to accurately represent these quadratic curves. How can we construct a corresponding one for a given quadratic curve parameter (such as the circle center and radius?

In the conical cut-off line, parabola does not need to be expressed by rational functions, so it is the simplest quadratic curve in the form. First, let's start by simply learning how to convert a parabolic curve from an implicit equation to a form of a curve.

First, let's briefly review the knowledge about parabolic in high school mathematics, as shown in a chart about the parabolic equation, focus coordinate, and inline equation in my high school mathematics textbook:

Figure 1.1 parabola fuction

In opencascade, the implicit equation corresponding to the parabolic curve represents gp_parab/gp_parab2d. This article mainly describes how to convert gp_parab2d to a green curve in opencascade.

**2. parametric representations**

In the application of CAD/CAM, there are two important parameter representations for the conical cut-off line: rational and maximum inner area (rational and Maximum Inscribed area forms ). The two parabolic forms are the same, as shown below:

Some rational parameter representations of the conical cut-off line may be quite poorly parameterized, that is, the parameter values of the even distribution correspond to the points with uneven distribution on the curve. Using Linear rational functions to re-parameterize a rational curve can change (and thus may be improved) its parameterization.

Assume that C (u) = (x (u), y (u) is a parameter representation of the conical cut line at the standard position. Now, the parameter equation given for the parabolic curve is also the above formula, which is a good parameterization: For any given integer N and parameter boundary A and B, take n equal-interval distribution parameters:

Points C (U1), C (U2),..., C (un) form the n-1 side Polygon on the curve. Its closed polygon has the largest inner area.

The node vector can be obtained based on the maximum inner area representation.

**3. Conversion Algorithm**

To convert an implicitly expressed parabolic equation to a curve (a special case of a rational spline), you must determine the following information about the curve: node vector, Weight Factor, number of times, and control vertex.

Because the parabolic curve is a quadratic curve, the number of times of the corresponding curve is also 2. The number of control vertices is 3 because the values are expressed by a rational bezr curve.

The node vector can be determined by the maximum inner area representation. The following figure shows the remaining data. The representation of the arc of the quadratic rational bezr curve obtained from the formula of the rational bezr curve is as follows:

K is the shape constant factor. The formula is as follows:

It can be proved that different weights are selected for the control vertices of the same group. As long as the shape factor K is equal, the quadratic rational bezr curve determined by them is the same curve segment, different weights correspond to different parameters, and quadratic curves can be classified based on Shape Invariant factors:

V k = 0; indicates the degraded quadratic curve: a pair of linear segments p0p1 and P1P2;

V kε [0, 1]; indicates a hyperbolic state;

V k = 1; parabolic;

V kε [1, + ∞]; indicates an elliptic;

V k = + ∞; indicates the line segment connecting P0 and P2;

In practice, we choose ω 0 = ω 2 = 1 as the standard parameterization. In this case, ω 1 = 1 is obtained from the formula K of the shape factor. Therefore, the parabolic weight factor is determined, that is, ω 0 = ω 1 = ω 2 = 1.

Figure 3.1 different weights ω 1 defined by the taper cut line

We can see from the quadratic rational bezr curve formula that when u = 0 and U = 1, C (0) = P0, C (1) = P2, that is, the curve passes through the first and last vertices of the feature polygon. Therefore, we can determine the two control vertices P0 and P2 of the parabolic curve, and only the last P1 vertex is not determined.

Point P1 can be calculated by the formula column equation of the quadratic rational bezr curve, but this is not a convenient method. A more convenient method is to specify the third point on this curve, which corresponds to a specific parameter, such as U = 1/2. Point S = C (1/2) is the shoulder point of the conical cut line, as shown in Figure 3.1. The following formula is used to substitute u = 1/2 into a quadratic rational bezr:

M is the midpoint of the string p0p2. Shoulder point S = C (1/2 ). Therefore, the P1 point can be determined from the above formula. The calculation of each control vertex is as follows:

If the start and end ranges of a parabolic curve are [UF, UL], P0 = (x0, y0) = (x0, UF) is adopted because the curve passes through the vertex of the feature polygon ). It is also known from the parabolic parameter equation:

Likewise, we can calculate the coordinates of P2 through the last point and list them as follows:

Based on the formula for calculating shoulder point S, enter Sy = Y1 = C (U1) = (UF + UL)/2 to get the following:

So the coordinates of Point P1 are:

So far, the three control vertices P0, P1, and P2. That is to say, the required data is obtained by using the parabolic form (OR. Let's take a look at the implementation code in opencascade.

**4. Code Analysis**

The math tool of opencascade has a set of covert to convert the conical curve and surface to the green curve and surface. The class for converting parabolic data is convert_parabolatobsplinecurve. The implementation code is as follows:

//=======================================================================//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);}

The code above shows that the number of curves is set to 2 first, and then the node vector is set to [UF, UL, UL], that is to say, the weight of the first parameter UF and the last parameter ul is three. The Node vector shows that the converted curve of the curve is the bezr curve.

The weights of the three control vertices are also set to 1. The calculation methods for the three control vertices are described in the previous section. The key is the computing of Point P1. The above calculation method is only personal opinion. Welcome to discuss and exchange.

At last, according to the Affine immutability of the rational curve, the expression of the rotation, translation, and scaling of the rational curve does not change, but the control point changes. The new control point can be obtained through the transformation of the original control point. That is to say, to perform an affine transformation on a rational bezr curve, you only need to perform a transformation on its control points.

The use of the conversion class of the conical cut line is very simple, and the computation is completed in the constructor. The following is a specific example of converting a parabolic curve to a non-green curve to describe its usage.

/** Copyright (c) 2014 eryar All Rights Reserved.** File : Main.cpp* Author : [email protected]* 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;}

At the beginning of the program, have_config_h needs to be defined, which is different from the programming definition of the Win32 in windows. Shows the program output result:

Figure 4.1 convert parabola to bspline curve result

**5. Conclusion**

One of the advantages of the service is to unify the representation of curve and surface, that is, it can not only represent a Free Curve and surface, but also accurately represent a Cone Curve and surface. The parabolic curve is the simplest conical cut-off line. It starts from the simple parabolic curve to the curve of the rectangle, and learns how to express the conical cut-off line by using the curve of the curve.

For the first time, Debian was used for programming. A lightweight IDE development tool codelite was selected, which is similar to Visual Studio. During this period, the dynamic library cannot be found when the referenced directory is included and the program is running. Shows how to add a reference library path to codelite:

Figure 5.1 set library path and add libraries in codelite

After the reference library is added, the Link error is solved, but the program runs directly and the similar problem is found in windows, that is, the dynamic library of dependency is missing, shows how to use the LLD command to check program dependencies. Finally, the problem is solved by adding the directory where the dynamic library is located to lD. So. conf. The related commands are as follows:

# Cat/etc/lD. So. conf

Include lD. So. conf. d/*. conf

# Echo "/home/eryar/opencascade-6.7.1/lib">/etc/lD. So. conf

# Ldconfig

Note: The preceding Command requires the root permission.

Figure 5.2 use LLD command to check depends

By solving the above problems, we can adapt to the use of codelite development programs in Debian.

**6. References**

1. Middle School Mathematics room of People's Education Press. Second Book of Mathematics (I). People's Education Press. 2000

2. Translated by Zhao Yu, Mu guowang, and Wang lanzhu. Non-Uniform Rational B-spline. Tsinghua University Press. 2010

3. Wang renhong, Li chongjun, Zhu chungang. tutorial on Computational ry, Science Press. 2008

Pdf version and sample code: opencascade conic to bspline curves-parabola

Opencascade conic to bspline curves-parabola