1 //File Convert_EllipseToBSplineCurve.cxx
5 #include <Convert_EllipseToBSplineCurve.ixx>
7 #include <TColgp_HArray1OfPnt2d.hxx>
8 #include <TColStd_HArray1OfReal.hxx>
9 #include <TColStd_HArray1OfInteger.hxx>
10 #include <TColStd_Array1OfReal.hxx>
11 #include <TColgp_Array1OfPnt2d.hxx>
14 #include <gp_Ax2d.hxx>
15 #include <gp_Dir2d.hxx>
16 #include <gp_Trsf2d.hxx>
18 #include <Precision.hxx>
21 //To avoid use of persistent tables in the fields
22 //the tables are dimensioned to the maximum (TheNbKnots and TheNbPoles)
23 //that correspond to the full circle. For an arc of circle there is a
24 //need of less poles and nodes, that is why the fields
25 //nbKnots and nbPoles are present and updated in the
26 //constructor of an arc of B-spline circle to take into account
27 //the real number of poles and nodes.
31 // Reference : Rational B-spline for Curve and Surface Representation
32 // Wayne Tiller CADG September 1983
34 // x(t) = (1 - t^2) / (1 + t^2)
35 // y(t) = 2 t / (1 + t^2)
37 // then t = Sqrt(2) u / ((Sqrt(2) - 2) u + 2)
39 // => u = 2 t / (Sqrt(2) + (2 - Sqrt(2)) t)
41 //=======================================================================
42 //function : Convert_EllipseToBSplineCurve
43 //purpose : this constructs a periodic Ellipse
44 //=======================================================================
46 Convert_EllipseToBSplineCurve::Convert_EllipseToBSplineCurve
47 (const gp_Elips2d& E, const Convert_ParameterisationType Parameterisation)
48 :Convert_ConicToBSplineCurve(0,0,0){
55 Handle(TColStd_HArray1OfReal) CosNumeratorPtr,
63 if (Parameterisation != Convert_TgtThetaOver2 &&
64 Parameterisation != Convert_RationalC1) {
65 // If BuildCosAndSin cannot manage the periodicity
67 isperiodic = Standard_False;
68 Convert_ConicToBSplineCurve::
69 BuildCosAndSin(Parameterisation,
79 isperiodic = Standard_True;
80 Convert_ConicToBSplineCurve::
81 BuildCosAndSin(Parameterisation,
90 nbPoles = CosNumeratorPtr->Length();
91 nbKnots = knots->Length();
94 new TColgp_HArray1OfPnt2d(1,nbPoles) ;
97 gp_Dir2d Ox = E.XAxis().Direction();
98 gp_Dir2d Oy = E.YAxis().Direction();
100 Trsf.SetTransformation( E.XAxis(), gp::OX2d());
101 if ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.0e0) {
108 // Replace the bspline in the mark of the circle.
109 // and calculate the weight of the bspline.
111 for (ii = 1; ii <= nbPoles ; ii++) {
112 poles->ChangeArray1()(ii).SetCoord(1, R * CosNumeratorPtr->Value(ii)) ;
113 poles->ChangeArray1()(ii).SetCoord(2, value * SinNumeratorPtr->Value(ii)) ;
114 poles->ChangeArray1()(ii).Transform( Trsf);
118 //=======================================================================
119 //function : Convert_EllipseToBSplineCurve
120 //purpose : this constructs a non periodic Ellipse
121 //=======================================================================
123 Convert_EllipseToBSplineCurve::Convert_EllipseToBSplineCurve
124 (const gp_Elips2d& E,
125 const Standard_Real UFirst,
126 const Standard_Real ULast,
127 const Convert_ParameterisationType Parameterisation)
128 :Convert_ConicToBSplineCurve(0,0,0)
131 Standard_Real Tol = Precision::PConfusion();
132 Standard_Real delta = ULast - UFirst;
134 Standard_DomainError_Raise_if( (delta > (2*M_PI+Tol)) || (delta <= 0.0e0),
135 "Convert_EllipseToBSplineCurve");
137 Standard_Real R, r, value;
138 Handle(TColStd_HArray1OfReal) CosNumeratorPtr, SinNumeratorPtr;
143 isperiodic = Standard_False;
144 Convert_ConicToBSplineCurve::BuildCosAndSin(Parameterisation,
154 nbPoles = CosNumeratorPtr->Length();
155 nbKnots = knots->Length();
157 poles = new TColgp_HArray1OfPnt2d(1,nbPoles) ;
159 gp_Dir2d Ox = E.XAxis().Direction();
160 gp_Dir2d Oy = E.YAxis().Direction();
162 Trsf.SetTransformation( E.XAxis(), gp::OX2d());
163 if ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.0e0) {
170 // Replace the bspline in the mark of the circle.
171 // and calculate the weight of the bspline.
173 for (ii = 1; ii <= nbPoles ; ii++) {
174 poles->ChangeArray1()(ii).SetCoord(1, R * CosNumeratorPtr->Value(ii)) ;
175 poles->ChangeArray1()(ii).SetCoord(2, value * SinNumeratorPtr->Value(ii)) ;
176 poles->ChangeArray1()(ii).Transform( Trsf);