1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
22 #include <Convert_HyperbolaToBSplineCurve.ixx>
23 #include <TColgp_HArray1OfPnt2d.hxx>
24 #include <TColStd_HArray1OfReal.hxx>
25 #include <TColStd_HArray1OfInteger.hxx>
26 #include <TColStd_Array1OfReal.hxx>
27 #include <TColgp_Array1OfPnt2d.hxx>
30 #include <gp_Ax2d.hxx>
31 #include <gp_Dir2d.hxx>
32 #include <gp_Trsf2d.hxx>
34 static Standard_Integer TheDegree = 2;
35 static Standard_Integer MaxNbKnots = 2;
36 static Standard_Integer MaxNbPoles = 3;
39 //=======================================================================
40 //function : Convert_HyperbolaToBSplineCurve
42 //=======================================================================
44 Convert_HyperbolaToBSplineCurve::Convert_HyperbolaToBSplineCurve
46 const Standard_Real U1,
47 const Standard_Real U2 )
49 : Convert_ConicToBSplineCurve (MaxNbPoles, MaxNbKnots, TheDegree)
51 Standard_DomainError_Raise_if( Abs(U2 - U1) < Epsilon(0.),
52 "Convert_ParabolaToBSplineCurve");
54 Standard_Real UF = Min (U1, U2);
55 Standard_Real UL = Max( U1, U2);
59 isperiodic = Standard_False;
60 knots->ChangeArray1()(1) = UF; mults->ChangeArray1()(1) = 3;
61 knots->ChangeArray1()(2) = UL; mults->ChangeArray1()(2) = 3;
63 // construction of hyperbola in the reference xOy.
65 Standard_Real R = H.MajorRadius();
66 Standard_Real r = H.MinorRadius();
67 gp_Dir2d Ox = H.Axis().XDirection();
68 gp_Dir2d Oy = H.Axis().YDirection();
69 Standard_Real S = ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.) ? 1 : -1;
71 // poles expressed in the reference mark
72 // the 2nd pole is at the intersection of 2 tangents to the curve
73 // at points P(UF), P(UL)
74 // the weight of this pole is equal to : Cosh((UL-UF)/2)
76 weights->ChangeArray1()(1) = 1.;
77 weights->ChangeArray1()(2) = Cosh((UL-UF)/2);
78 weights->ChangeArray1()(3) = 1.;
80 Standard_Real delta = Sinh(UL-UF);
81 Standard_Real x = R * ( Sinh(UL) - Sinh(UF)) / delta;
82 Standard_Real y = S * r * ( Cosh(UL) - Cosh(UF)) / delta;
83 poles->ChangeArray1()(1) = gp_Pnt2d( R * Cosh(UF), S * r * Sinh(UF));
84 poles->ChangeArray1()(2) = gp_Pnt2d( x, y);
85 poles->ChangeArray1()(3) = gp_Pnt2d( R * Cosh(UL), S * r * Sinh(UL));
87 // replace the bspline in the mark of the hyperbola
89 Trsf.SetTransformation( H.Axis().XAxis(), gp::OX2d());
90 poles->ChangeArray1()(1).Transform( Trsf);
91 poles->ChangeArray1()(2).Transform( Trsf);
92 poles->ChangeArray1()(3).Transform( Trsf);