1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 //--------------------------------------------------------------------
17 //--------------------------------------------------------------------
18 //#59 rln 29.12.98 PRO17015
21 #include <gp_Dir2d.hxx>
22 #include <gp_GTrsf.hxx>
24 #include <gp_Pnt2d.hxx>
26 #include <IGESGeom_ConicArc.hxx>
27 #include <Standard_Type.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(IGESGeom_ConicArc,IGESData_IGESEntity)
31 IGESGeom_ConicArc::IGESGeom_ConicArc () { }
34 void IGESGeom_ConicArc::Init
35 (const Standard_Real A, const Standard_Real B,
36 const Standard_Real C, const Standard_Real D, const Standard_Real E,
37 const Standard_Real F, const Standard_Real ZT, const gp_XY& aStart,
50 Standard_Integer fn = FormNumber();
51 if (fn == 0) fn = ComputedFormNumber();
52 InitTypeAndForm(104,fn);
55 Standard_Boolean IGESGeom_ConicArc::OwnCorrect ()
57 Standard_Integer cfn = ComputedFormNumber();
58 if (FormNumber() == cfn) return Standard_False;
59 InitTypeAndForm(104,cfn);
63 void IGESGeom_ConicArc::Equation
64 (Standard_Real& A, Standard_Real& B, Standard_Real& C, Standard_Real& D,
65 Standard_Real& E, Standard_Real& F) const
75 Standard_Real IGESGeom_ConicArc::ZPlane () const
80 gp_Pnt2d IGESGeom_ConicArc::StartPoint () const
82 gp_Pnt2d start(theStart.X(), theStart.Y());
86 gp_Pnt IGESGeom_ConicArc::TransformedStartPoint () const
88 gp_XYZ start(theStart.X(), theStart.Y(), theZT);
89 if (HasTransf()) Location().Transforms(start);
90 gp_Pnt transStart(start);
94 gp_Pnt2d IGESGeom_ConicArc::EndPoint () const
96 gp_Pnt2d end(theEnd.X(), theEnd.Y());
100 gp_Pnt IGESGeom_ConicArc::TransformedEndPoint () const
102 gp_XYZ end(theEnd.X(), theEnd.Y(), theZT);
103 if (HasTransf()) Location().Transforms(end);
104 gp_Pnt transEnd(end);
108 Standard_Integer IGESGeom_ConicArc::ComputedFormNumber () const
110 Standard_Real eps,eps2,eps4;
111 eps = 1.E-08; eps2 = eps*eps; eps4 = eps2*eps2;//#59 rln
112 Standard_Real Q1 = theA * (theC*theF - theE*theE/4.)
113 + theB/2. * (theE*theD/4. - theB*theF/2.)
114 + theD/2. * (theB*theE/4. - theC*theD/2.);
115 Standard_Real Q2 = theA*theC - theB*theB/4;
116 Standard_Real Q3 = theA + theC;
119 //#59 rln 29.12.98 PRO17015 face#67, ellipse
120 //each Qi has its own dimension:
121 //[Q1] = L^-4, [Q2]=L^-4, [Q3]=L^-2
122 if (Q2 > eps4 && Q1*Q3 < 0 ) return 1; // Ellipse
123 if (Q2 < -eps4 && Abs (Q1) > eps4) return 2; // Hyperbola
124 if (Abs (Q2) <= eps4 && Abs (Q1) > eps4) return 3; // Parabola
128 Standard_Boolean IGESGeom_ConicArc::IsFromParabola () const
130 Standard_Integer fn = FormNumber();
131 if (fn == 0) fn = ComputedFormNumber();
135 Standard_Boolean IGESGeom_ConicArc::IsFromEllipse () const
137 Standard_Integer fn = FormNumber();
138 if (fn == 0) fn = ComputedFormNumber();
142 Standard_Boolean IGESGeom_ConicArc::IsFromHyperbola () const
144 Standard_Integer fn = FormNumber();
145 if (fn == 0) fn = ComputedFormNumber();
149 Standard_Boolean IGESGeom_ConicArc::IsClosed () const
151 return ((theStart.X() == theEnd.X()) && (theStart.Y() == theEnd.Y()));
154 gp_Dir IGESGeom_ConicArc::Axis () const
156 gp_Dir axis(0.0 , 0.0, 1.0);
162 gp_Dir IGESGeom_ConicArc::TransformedAxis () const
164 gp_XYZ axis(0.0 , 0.0, 1.0);
165 if (!HasTransf()) return gp_Dir(axis);
166 gp_GTrsf loc = Location();
167 loc.SetTranslationPart (gp_XYZ(0.,0.,0.));
168 loc.Transforms(axis);
173 void IGESGeom_ConicArc::Definition
174 (gp_Pnt& Center, gp_Dir& MainAxis,
175 Standard_Real& Rmin, Standard_Real& Rmax) const
177 Standard_Real Xcen,Ycen, Xax,Yax;
178 ComputedDefinition (Xcen,Ycen, Xax,Yax, Rmin,Rmax);
179 Center.SetCoord (Xcen,Ycen,theZT);
180 MainAxis.SetCoord (Xax,Yax,0.);
183 void IGESGeom_ConicArc::TransformedDefinition
184 (gp_Pnt& Center, gp_Dir& MainAxis,
185 Standard_Real& Rmin, Standard_Real& Rmax) const
188 Definition (Center,MainAxis,Rmin,Rmax);
191 Standard_Real Xcen,Ycen, Xax,Yax;
192 ComputedDefinition (Xcen,Ycen, Xax,Yax, Rmin,Rmax);
193 gp_GTrsf loc = Location();
194 gp_XYZ cen (Xcen,Ycen,theZT);
195 gp_XYZ axis (Xax, Yax, 0.);
196 loc.Transforms (cen);
197 loc.SetTranslationPart (gp_XYZ(0.,0.,0.));
198 loc.Transforms (axis);
199 Center.SetCoord (cen.X(), cen.Y(), cen.Z() );
200 MainAxis.SetCoord (axis.X(),axis.Y(),axis.Z());
204 void IGESGeom_ConicArc::ComputedDefinition
205 (Standard_Real& Xcen, Standard_Real& Ycen,
206 Standard_Real& Xax, Standard_Real& Yax,
207 Standard_Real& Rmin, Standard_Real& Rmax) const
209 Standard_Real a,b,c,d,e,f;
210 // conic : a*x2 + 2*b*x*y + c*y2 + 2*d*x + 2*e*y + f = 0.
211 Equation (a,b,c,d,e,f);
212 b = b/2.; d = d/2.; e = e/2.; // chgt de variable
214 Standard_Real eps = 1.E-08; // ?? comme ComputedForm
216 if (IsFromParabola()) {
217 Rmin = Rmax = -1.; // rayons : yena pas
218 if ( (Abs(a) <= eps) && (Abs(b) <= eps)) {
219 Xcen = (f*c - e*e) /c /d /2.;
221 Standard_Real focal = -d/c;
222 Xax = (focal >= 0 ? 1. : -1.);
224 Rmin = Rmax = Abs(focal);
227 Standard_Real ss = a+c;
228 Standard_Real cc = - (a*d+b*e) / ss;
229 Standard_Real dd = d + (c*d - b*e) / ss;
230 Standard_Real fc = (a*e - b*d) / ss;
231 Standard_Real ee = e + fc;
233 Standard_Real dn = a*ee - dd*b;
234 Xcen = ( cc*ee + f*b) / dn;
235 Ycen = (-cc*dd - f*a) / dn;
237 Standard_Real teta = M_PI/2.;
238 if (Abs(b) > eps) teta = ATan (-a/b);
239 if (fc < 0) teta += M_PI;
243 Rmin = Rmax = Abs(fc)/sqrt(a*a+b*b)/2.;
248 // -> Conique a centre, cas general
249 // On utilise les Determinants des matrices :
251 // gdet (3x3) = | b c e | et pdet (2X2) = | a b |
254 Standard_Real gdet = a*c*f + 2*b*d*e - c*d*d - a*e*e - b*b*f;
255 Standard_Real pdet = a*c - b*b;
257 Xcen = (b*e - c*d) / pdet;
258 Ycen = (b*d - a*e) / pdet;
260 Standard_Real term1 = a-c;
261 Standard_Real term2 = 2*b;
265 if (Abs(term1)< gp::Resolution()) {
270 Standard_Real t2d = term2/term1; //skl 28.12.2001
271 cos2t = 1./sqrt(1+t2d*t2d);
272 auxil = sqrt (term1*term1 + term2*term2);
275 Standard_Real cost = sqrt ( (1+cos2t)/2. );
276 Standard_Real sint = sqrt ( (1-cos2t)/2. );
278 Standard_Real aprim = (a+c+auxil)/2.;
279 Standard_Real cprim = (a+c-auxil)/2.;
281 term1 = -gdet/(aprim*pdet);
282 term2 = -gdet/(cprim*pdet);
284 if (IsFromEllipse()) {
287 Rmin = sqrt ( term1);
288 Rmax = sqrt ( term2);
289 if(Rmax<Rmin){ //skl 28.12.2001
290 Rmax = sqrt ( term1);
291 Rmin = sqrt ( term2);
294 else if (term1 <= eps){
297 Rmin = sqrt (-term1);
303 Rmin = sqrt (-term2);