1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
17 #include <Convert_ParabolaToBSplineCurve.hxx>
19 #include <gp_Ax2d.hxx>
20 #include <gp_Dir2d.hxx>
21 #include <gp_Parab2d.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>
29 static Standard_Integer TheDegree = 2;
30 static Standard_Integer MaxNbKnots = 2;
31 static Standard_Integer MaxNbPoles = 3;
33 //=======================================================================
34 //function : Convert_ParabolaToBSplineCurve
36 //=======================================================================
38 Convert_ParabolaToBSplineCurve::Convert_ParabolaToBSplineCurve
39 (const gp_Parab2d& Prb,
40 const Standard_Real U1 ,
41 const Standard_Real U2 )
42 : Convert_ConicToBSplineCurve (MaxNbPoles, MaxNbKnots, TheDegree)
44 Standard_DomainError_Raise_if( Abs(U2 - U1) < Epsilon(0.),
45 "Convert_ParabolaToBSplineCurve");
47 Standard_Real UF = Min (U1, U2);
48 Standard_Real UL = Max( U1, U2);
50 Standard_Real p = Prb.Parameter();
54 isperiodic = Standard_False;
55 knots->ChangeArray1()(1) = UF; mults->ChangeArray1()(1) = 3;
56 knots->ChangeArray1()(2) = UL; mults->ChangeArray1()(2) = 3;
58 weights->ChangeArray1()(1) = 1.;
59 weights->ChangeArray1()(2) = 1.;
60 weights->ChangeArray1()(3) = 1.;
62 gp_Dir2d Ox = Prb.Axis().XDirection();
63 gp_Dir2d Oy = Prb.Axis().YDirection();
64 Standard_Real S = ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.) ? 1 : -1;
67 // poles expressed in the reference mark
68 poles->ChangeArray1()(1) =
69 gp_Pnt2d( ( UF * UF) / ( 2. * p), S * UF );
70 poles->ChangeArray1()(2) =
71 gp_Pnt2d( ( UF * UL) / ( 2. * p), S * ( UF + UL) / 2. );
72 poles->ChangeArray1()(3) =
73 gp_Pnt2d( ( UL * UL) / ( 2. * p), S * UL );
75 // replace the bspline in the mark of the parabola
77 Trsf.SetTransformation( Prb.Axis().XAxis(), gp::OX2d());
78 poles->ChangeArray1()(1).Transform( Trsf);
79 poles->ChangeArray1()(2).Transform( Trsf);
80 poles->ChangeArray1()(3).Transform( Trsf);