1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 //JCV 16/10/91
16
17 #include <Convert_HyperbolaToBSplineCurve.hxx>
18 #include <gp.hxx>
19 #include <gp_Ax2d.hxx>
20 #include <gp_Dir2d.hxx>
21 #include <gp_Hypr2d.hxx>
22 #include <gp_Trsf2d.hxx>
23 #include <TColgp_Array1OfPnt2d.hxx>
24 #include <TColgp_HArray1OfPnt2d.hxx>
25 #include <TColStd_Array1OfReal.hxx>
26 #include <TColStd_HArray1OfInteger.hxx>
27 #include <TColStd_HArray1OfReal.hxx>
28
29 static Standard_Integer TheDegree = 2;
30 static Standard_Integer MaxNbKnots = 2;
31 static Standard_Integer MaxNbPoles = 3;
32
33
34 //=======================================================================
35 //function : Convert_HyperbolaToBSplineCurve
36 //purpose :
37 //=======================================================================
38
Convert_HyperbolaToBSplineCurve(const gp_Hypr2d & H,const Standard_Real U1,const Standard_Real U2)39 Convert_HyperbolaToBSplineCurve::Convert_HyperbolaToBSplineCurve
40 (const gp_Hypr2d& H ,
41 const Standard_Real U1,
42 const Standard_Real U2 )
43
44 : Convert_ConicToBSplineCurve (MaxNbPoles, MaxNbKnots, TheDegree)
45 {
46 Standard_DomainError_Raise_if( Abs(U2 - U1) < Epsilon(0.),
47 "Convert_ParabolaToBSplineCurve");
48
49 Standard_Real UF = Min (U1, U2);
50 Standard_Real UL = Max( U1, U2);
51
52 nbPoles = 3;
53 nbKnots = 2;
54 isperiodic = Standard_False;
55 knots->ChangeArray1()(1) = UF; mults->ChangeArray1()(1) = 3;
56 knots->ChangeArray1()(2) = UL; mults->ChangeArray1()(2) = 3;
57
58 // construction of hyperbola in the reference xOy.
59
60 Standard_Real R = H.MajorRadius();
61 Standard_Real r = H.MinorRadius();
62 gp_Dir2d Ox = H.Axis().XDirection();
63 gp_Dir2d Oy = H.Axis().YDirection();
64 Standard_Real S = ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.) ? 1 : -1;
65
66 // poles expressed in the reference mark
67 // the 2nd pole is at the intersection of 2 tangents to the curve
68 // at points P(UF), P(UL)
69 // the weight of this pole is equal to : Cosh((UL-UF)/2)
70
71 weights->ChangeArray1()(1) = 1.;
72 weights->ChangeArray1()(2) = Cosh((UL-UF)/2);
73 weights->ChangeArray1()(3) = 1.;
74
75 Standard_Real delta = Sinh(UL-UF);
76 Standard_Real x = R * ( Sinh(UL) - Sinh(UF)) / delta;
77 Standard_Real y = S * r * ( Cosh(UL) - Cosh(UF)) / delta;
78 poles->ChangeArray1()(1) = gp_Pnt2d( R * Cosh(UF), S * r * Sinh(UF));
79 poles->ChangeArray1()(2) = gp_Pnt2d( x, y);
80 poles->ChangeArray1()(3) = gp_Pnt2d( R * Cosh(UL), S * r * Sinh(UL));
81
82 // replace the bspline in the mark of the hyperbola
83 gp_Trsf2d Trsf;
84 Trsf.SetTransformation( H.Axis().XAxis(), gp::OX2d());
85 poles->ChangeArray1()(1).Transform( Trsf);
86 poles->ChangeArray1()(2).Transform( Trsf);
87 poles->ChangeArray1()(3).Transform( Trsf);
88 }
89