0031501: Foundation Classes, Message_Printer - remove theToPutEndl argument -- prepar...
[occt.git] / src / IGESGeom / IGESGeom_ConicArc.cxx
CommitLineData
b311480e 1// Created by: CKY / Contract Toubro-Larsen
2// Copyright (c) 1993-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
7fd59977 6//
d5f74e42 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
973c2be1 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.
7fd59977 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
16//--------------------------------------------------------------------
7fd59977 17//--------------------------------------------------------------------
18//#59 rln 29.12.98 PRO17015
19
42cf5bc1 20#include <gp_Dir.hxx>
7fd59977 21#include <gp_Dir2d.hxx>
22#include <gp_GTrsf.hxx>
42cf5bc1 23#include <gp_Pnt.hxx>
24#include <gp_Pnt2d.hxx>
25#include <gp_XY.hxx>
26#include <IGESGeom_ConicArc.hxx>
27#include <Standard_Type.hxx>
7fd59977 28
92efcf78 29IMPLEMENT_STANDARD_RTTIEXT(IGESGeom_ConicArc,IGESData_IGESEntity)
30
b311480e 31IGESGeom_ConicArc::IGESGeom_ConicArc () { }
7fd59977 32
33
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,
38 const gp_XY& anEnd)
39{
40 theA = A;
41 theB = B;
42 theC = C;
43 theD = D;
44 theE = E;
45 theF = F;
46 theZT = ZT;
47 theStart = aStart;
48 theEnd = anEnd;
49
50 Standard_Integer fn = FormNumber();
51 if (fn == 0) fn = ComputedFormNumber();
52 InitTypeAndForm(104,fn);
53}
54
55 Standard_Boolean IGESGeom_ConicArc::OwnCorrect ()
56{
57 Standard_Integer cfn = ComputedFormNumber();
58 if (FormNumber() == cfn) return Standard_False;
59 InitTypeAndForm(104,cfn);
60 return Standard_True;
61}
62
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
66{
67 A = theA;
68 B = theB;
69 C = theC;
70 D = theD;
71 E = theE;
72 F = theF;
73}
74
75 Standard_Real IGESGeom_ConicArc::ZPlane () const
76{
77 return theZT;
78}
79
80 gp_Pnt2d IGESGeom_ConicArc::StartPoint () const
81{
82 gp_Pnt2d start(theStart.X(), theStart.Y());
83 return start;
84}
85
86 gp_Pnt IGESGeom_ConicArc::TransformedStartPoint () const
87{
88 gp_XYZ start(theStart.X(), theStart.Y(), theZT);
89 if (HasTransf()) Location().Transforms(start);
90 gp_Pnt transStart(start);
91 return transStart;
92}
93
94 gp_Pnt2d IGESGeom_ConicArc::EndPoint () const
95{
96 gp_Pnt2d end(theEnd.X(), theEnd.Y());
97 return end;
98}
99
100 gp_Pnt IGESGeom_ConicArc::TransformedEndPoint () const
101{
102 gp_XYZ end(theEnd.X(), theEnd.Y(), theZT);
103 if (HasTransf()) Location().Transforms(end);
104 gp_Pnt transEnd(end);
105 return transEnd;
106}
107
108 Standard_Integer IGESGeom_ConicArc::ComputedFormNumber () const
109{
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;
117
118// Resultats
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
125 return 0;
126}
127
128 Standard_Boolean IGESGeom_ConicArc::IsFromParabola () const
129{
130 Standard_Integer fn = FormNumber();
131 if (fn == 0) fn = ComputedFormNumber();
132 return (fn == 3);
133}
134
135 Standard_Boolean IGESGeom_ConicArc::IsFromEllipse () const
136{
137 Standard_Integer fn = FormNumber();
138 if (fn == 0) fn = ComputedFormNumber();
139 return (fn == 1);
140}
141
142 Standard_Boolean IGESGeom_ConicArc::IsFromHyperbola () const
143{
144 Standard_Integer fn = FormNumber();
145 if (fn == 0) fn = ComputedFormNumber();
146 return (fn == 2);
147}
148
149 Standard_Boolean IGESGeom_ConicArc::IsClosed () const
150{
151 return ((theStart.X() == theEnd.X()) && (theStart.Y() == theEnd.Y()));
152}
153
154 gp_Dir IGESGeom_ConicArc::Axis () const
155{
156 gp_Dir axis(0.0 , 0.0, 1.0);
157 return axis;
158}
159
160// Valeurs calculees
161
162 gp_Dir IGESGeom_ConicArc::TransformedAxis () const
163{
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);
169 return gp_Dir(axis);
170}
171
172
173 void IGESGeom_ConicArc::Definition
174 (gp_Pnt& Center, gp_Dir& MainAxis,
175 Standard_Real& Rmin, Standard_Real& Rmax) const
176{
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.);
181}
182
183 void IGESGeom_ConicArc::TransformedDefinition
184 (gp_Pnt& Center, gp_Dir& MainAxis,
185 Standard_Real& Rmin, Standard_Real& Rmax) const
186{
187 if (!HasTransf()) {
188 Definition (Center,MainAxis,Rmin,Rmax);
189 return;
190 }
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());
201}
202
203
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
208{
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
213
214 Standard_Real eps = 1.E-08; // ?? comme ComputedForm
215
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.;
220 Ycen = e/c;
221 Standard_Real focal = -d/c;
222 Xax = (focal >= 0 ? 1. : -1.);
223 Yax = 0.;
224 Rmin = Rmax = Abs(focal);
225 }
226 else {
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;
232
233 Standard_Real dn = a*ee - dd*b;
234 Xcen = ( cc*ee + f*b) / dn;
235 Ycen = (-cc*dd - f*a) / dn;
236
c6541a0c 237 Standard_Real teta = M_PI/2.;
7fd59977 238 if (Abs(b) > eps) teta = ATan (-a/b);
c6541a0c 239 if (fc < 0) teta += M_PI;
7fd59977 240 Xax = Cos(teta);
241 Yax = Sin(teta);
242
243 Rmin = Rmax = Abs(fc)/sqrt(a*a+b*b)/2.;
244 }
245 }
246
247 else {
248 // -> Conique a centre, cas general
249 // On utilise les Determinants des matrices :
250 // | a b d |
251 // gdet (3x3) = | b c e | et pdet (2X2) = | a b |
252 // | d e f | | b c |
253
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;
256
257 Xcen = (b*e - c*d) / pdet;
258 Ycen = (b*d - a*e) / pdet;
259
260 Standard_Real term1 = a-c;
261 Standard_Real term2 = 2*b;
262 Standard_Real cos2t;
263 Standard_Real auxil;
264
a1096551 265 if (Abs(term1)< gp::Resolution()) {
7fd59977 266 cos2t = 1.;
a1096551 267 auxil = term2;
7fd59977 268 }
269 else {
270 Standard_Real t2d = term2/term1; //skl 28.12.2001
271 cos2t = 1./sqrt(1+t2d*t2d);
272 auxil = sqrt (term1*term1 + term2*term2);
273 }
274
275 Standard_Real cost = sqrt ( (1+cos2t)/2. );
276 Standard_Real sint = sqrt ( (1-cos2t)/2. );
277
278 Standard_Real aprim = (a+c+auxil)/2.;
279 Standard_Real cprim = (a+c-auxil)/2.;
280
281 term1 = -gdet/(aprim*pdet);
282 term2 = -gdet/(cprim*pdet);
283
284 if (IsFromEllipse()) {
285 Xax = cost;
286 Yax = sint;
287 Rmin = sqrt ( term1);
288 Rmax = sqrt ( term2);
289 if(Rmax<Rmin){ //skl 28.12.2001
290 Rmax = sqrt ( term1);
291 Rmin = sqrt ( term2);
292 }
293 }
294 else if (term1 <= eps){
295 Xax = -sint;
296 Yax = cost;
297 Rmin = sqrt (-term1);
298 Rmax = sqrt (term2);
299 }
300 else {
301 Xax = cost;
302 Yax = sint;
303 Rmin = sqrt (-term2);
304 Rmax = sqrt (term1);
305 }
306 }
307}