0027234: Code duplication: Convert_CompBezierCurvesToBSplineCurve* in ShapeConstruct
[occt.git] / src / Convert / Convert_HyperbolaToBSplineCurve.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15//JCV 16/10/91
16
42cf5bc1 17#include <Convert_HyperbolaToBSplineCurve.hxx>
7fd59977 18#include <gp.hxx>
19#include <gp_Ax2d.hxx>
20#include <gp_Dir2d.hxx>
42cf5bc1 21#include <gp_Hypr2d.hxx>
7fd59977 22#include <gp_Trsf2d.hxx>
42cf5bc1 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>
7fd59977 28
29static Standard_Integer TheDegree = 2;
30static Standard_Integer MaxNbKnots = 2;
31static Standard_Integer MaxNbPoles = 3;
32
33
34//=======================================================================
35//function : Convert_HyperbolaToBSplineCurve
36//purpose :
37//=======================================================================
38
39Convert_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
0d969553 58 // construction of hyperbola in the reference xOy.
7fd59977 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
0d969553
Y
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)
7fd59977 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
0d969553 82 // replace the bspline in the mark of the hyperbola
7fd59977 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}