b311480e |
1 | // Created on: 1993-03-24 |
2 | // Created by: JCV |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <ElCLib.hxx> |
19 | #include <Geom2d_Ellipse.hxx> |
20 | #include <Geom2d_Geometry.hxx> |
7fd59977 |
21 | #include <gp.hxx> |
42cf5bc1 |
22 | #include <gp_Ax2d.hxx> |
23 | #include <gp_Ax22d.hxx> |
7fd59977 |
24 | #include <gp_Dir2d.hxx> |
42cf5bc1 |
25 | #include <gp_Elips2d.hxx> |
26 | #include <gp_Pnt2d.hxx> |
27 | #include <gp_Trsf2d.hxx> |
28 | #include <gp_Vec2d.hxx> |
7fd59977 |
29 | #include <gp_XYZ.hxx> |
7fd59977 |
30 | #include <Standard_ConstructionError.hxx> |
42cf5bc1 |
31 | #include <Standard_RangeError.hxx> |
32 | #include <Standard_Type.hxx> |
7fd59977 |
33 | |
92efcf78 |
34 | IMPLEMENT_STANDARD_RTTIEXT(Geom2d_Ellipse,Geom2d_Conic) |
35 | |
7fd59977 |
36 | typedef Geom2d_Ellipse Ellipse; |
7fd59977 |
37 | typedef gp_Ax2d Ax2d; |
38 | typedef gp_Dir2d Dir2d; |
39 | typedef gp_Pnt2d Pnt2d; |
40 | typedef gp_Vec2d Vec2d; |
41 | typedef gp_Trsf2d Trsf2d; |
42 | typedef gp_XY XY; |
43 | |
7fd59977 |
44 | //======================================================================= |
45 | //function : Copy |
46 | //purpose : |
47 | //======================================================================= |
48 | |
49 | Handle(Geom2d_Geometry) Geom2d_Ellipse::Copy() const |
50 | { |
c04c30b3 |
51 | Handle(Geom2d_Ellipse) E; |
7fd59977 |
52 | E = new Ellipse (pos, majorRadius, minorRadius); |
53 | return E; |
54 | } |
55 | |
56 | |
57 | //======================================================================= |
58 | //function : Geom2d_Ellipse |
59 | //purpose : |
60 | //======================================================================= |
61 | |
62 | Geom2d_Ellipse::Geom2d_Ellipse (const gp_Elips2d& E) { |
63 | |
64 | majorRadius = E.MajorRadius(); |
65 | minorRadius = E.MinorRadius(); |
66 | pos = E.Axis(); |
67 | } |
68 | |
69 | |
70 | |
71 | //======================================================================= |
72 | //function : Geom2d_Ellipse |
73 | //purpose : |
74 | //======================================================================= |
75 | |
76 | Geom2d_Ellipse::Geom2d_Ellipse (const Ax2d& MajorAxis, |
77 | const Standard_Real MajorRadius, |
78 | const Standard_Real MinorRadius, |
79 | const Standard_Boolean Sense) |
80 | :majorRadius (MajorRadius), minorRadius (MinorRadius){ |
81 | |
82 | if (MajorRadius < MinorRadius || MinorRadius < 0.0 ) { |
9775fa61 |
83 | throw Standard_ConstructionError(); |
7fd59977 |
84 | } |
85 | pos = gp_Ax22d(MajorAxis, Sense); |
86 | } |
87 | |
88 | |
89 | //======================================================================= |
90 | //function : Geom2d_Ellipse |
91 | //purpose : |
92 | //======================================================================= |
93 | |
94 | Geom2d_Ellipse::Geom2d_Ellipse (const gp_Ax22d& Axis, |
95 | const Standard_Real MajorRadius, |
96 | const Standard_Real MinorRadius) |
97 | : majorRadius (MajorRadius), minorRadius (MinorRadius) |
98 | { |
99 | if (MajorRadius < MinorRadius || MinorRadius < 0.0 ) { |
9775fa61 |
100 | throw Standard_ConstructionError(); |
7fd59977 |
101 | } |
102 | pos = Axis; |
103 | } |
104 | |
105 | |
106 | //======================================================================= |
107 | //function : SetElips2d |
108 | //purpose : |
109 | //======================================================================= |
110 | |
111 | void Geom2d_Ellipse::SetElips2d (const gp_Elips2d& E) |
112 | { |
113 | majorRadius = E.MajorRadius(); |
114 | minorRadius = E.MinorRadius(); |
115 | pos = E.Axis(); |
116 | } |
117 | |
118 | |
119 | //======================================================================= |
120 | //function : SetMajorRadius |
121 | //purpose : |
122 | //======================================================================= |
123 | |
124 | void Geom2d_Ellipse::SetMajorRadius (const Standard_Real MajorRadius) |
125 | { |
126 | if (MajorRadius < minorRadius) |
9775fa61 |
127 | throw Standard_ConstructionError(); |
7fd59977 |
128 | else |
129 | majorRadius = MajorRadius; |
130 | } |
131 | |
132 | |
133 | //======================================================================= |
134 | //function : SetMinorRadius |
135 | //purpose : |
136 | //======================================================================= |
137 | |
138 | void Geom2d_Ellipse::SetMinorRadius (const Standard_Real MinorRadius) |
139 | { |
140 | if (MinorRadius < 0 || majorRadius < MinorRadius) |
9775fa61 |
141 | { throw Standard_ConstructionError(); } |
7fd59977 |
142 | else |
143 | { minorRadius = MinorRadius; } |
144 | } |
145 | |
146 | |
147 | //======================================================================= |
148 | //function : Elips2d |
149 | //purpose : |
150 | //======================================================================= |
151 | |
152 | gp_Elips2d Geom2d_Ellipse::Elips2d () const |
153 | { |
154 | return gp_Elips2d (pos, majorRadius, minorRadius); |
155 | } |
156 | |
157 | //======================================================================= |
158 | //function : ReversedParameter |
159 | //purpose : |
160 | //======================================================================= |
161 | |
162 | Standard_Real Geom2d_Ellipse::ReversedParameter( const Standard_Real U) const |
163 | { |
c6541a0c |
164 | return (2. * M_PI - U); |
7fd59977 |
165 | } |
166 | |
167 | //======================================================================= |
168 | //function : Directrix1 |
169 | //purpose : |
170 | //======================================================================= |
171 | |
172 | Ax2d Geom2d_Ellipse::Directrix1 () const |
173 | { |
174 | gp_Elips2d Ev (pos, majorRadius, minorRadius); |
175 | return Ev.Directrix1(); |
176 | } |
177 | |
178 | |
179 | //======================================================================= |
180 | //function : Directrix2 |
181 | //purpose : |
182 | //======================================================================= |
183 | |
184 | Ax2d Geom2d_Ellipse::Directrix2 () const |
185 | { |
186 | gp_Elips2d Ev (pos, majorRadius, minorRadius); |
187 | return Ev.Directrix2(); |
188 | } |
189 | |
190 | |
191 | //======================================================================= |
192 | //function : Eccentricity |
193 | //purpose : |
194 | //======================================================================= |
195 | |
196 | Standard_Real Geom2d_Ellipse::Eccentricity () const |
197 | { |
198 | if (majorRadius == 0.0) |
199 | { return 0.0; } |
200 | else |
201 | { return |
202 | (Sqrt(majorRadius*majorRadius-minorRadius*minorRadius))/majorRadius; |
203 | } |
204 | } |
205 | |
206 | |
207 | //======================================================================= |
208 | //function : Focal |
209 | //purpose : |
210 | //======================================================================= |
211 | |
212 | Standard_Real Geom2d_Ellipse::Focal () const |
213 | { |
214 | return 2.0 * Sqrt(majorRadius * majorRadius - minorRadius * minorRadius); |
215 | } |
216 | |
217 | |
218 | //======================================================================= |
219 | //function : Focus1 |
220 | //purpose : |
221 | //======================================================================= |
222 | |
223 | Pnt2d Geom2d_Ellipse::Focus1 () const |
224 | { |
225 | Standard_Real C = Sqrt(majorRadius * majorRadius - minorRadius * minorRadius); |
226 | return Pnt2d (pos.Location().X() + C * pos.XDirection().X(), |
227 | pos.Location().Y() + C * pos.XDirection().Y()); |
228 | } |
229 | |
230 | |
231 | //======================================================================= |
232 | //function : Focus2 |
233 | //purpose : |
234 | //======================================================================= |
235 | |
236 | Pnt2d Geom2d_Ellipse::Focus2 () const |
237 | { |
238 | Standard_Real C = Sqrt(majorRadius * majorRadius - minorRadius * minorRadius); |
239 | return Pnt2d (pos.Location().X() - C * pos.XDirection().X(), |
240 | pos.Location().Y() - C * pos.XDirection().Y()); |
241 | } |
242 | |
243 | //======================================================================= |
244 | //function : MajorRadius |
245 | //purpose : |
246 | //======================================================================= |
247 | |
248 | Standard_Real Geom2d_Ellipse::MajorRadius () const |
249 | { |
250 | return majorRadius; |
251 | } |
252 | |
253 | //======================================================================= |
254 | //function : MinorRadius |
255 | //purpose : |
256 | //======================================================================= |
257 | |
258 | Standard_Real Geom2d_Ellipse::MinorRadius () const |
259 | { |
260 | return minorRadius; |
261 | } |
262 | |
263 | //======================================================================= |
264 | //function : Parameter |
265 | //purpose : |
266 | //======================================================================= |
267 | |
268 | Standard_Real Geom2d_Ellipse::Parameter () const |
269 | { |
270 | if (majorRadius == 0.0) |
271 | return 0.0; |
272 | else |
273 | return (minorRadius * minorRadius)/majorRadius; |
274 | } |
275 | |
276 | |
277 | //======================================================================= |
278 | //function : FirstParameter |
279 | //purpose : |
280 | //======================================================================= |
281 | |
282 | Standard_Real Geom2d_Ellipse::FirstParameter () const |
283 | { |
284 | return 0.0; |
285 | } |
286 | |
287 | //======================================================================= |
288 | //function : LastParameter |
289 | //purpose : |
290 | //======================================================================= |
291 | |
292 | Standard_Real Geom2d_Ellipse::LastParameter () const |
293 | { |
c6541a0c |
294 | return 2.0 * M_PI; |
7fd59977 |
295 | } |
296 | |
297 | //======================================================================= |
298 | //function : IsClosed |
299 | //purpose : |
300 | //======================================================================= |
301 | |
302 | Standard_Boolean Geom2d_Ellipse::IsClosed () const |
303 | { |
304 | return Standard_True; |
305 | } |
306 | |
307 | //======================================================================= |
308 | //function : IsPeriodic |
309 | //purpose : |
310 | //======================================================================= |
311 | |
312 | Standard_Boolean Geom2d_Ellipse::IsPeriodic () const |
313 | { |
314 | return Standard_True; |
315 | } |
316 | |
317 | //======================================================================= |
318 | //function : D0 |
319 | //purpose : |
320 | //======================================================================= |
321 | |
322 | void Geom2d_Ellipse::D0 (const Standard_Real U, Pnt2d& P) const |
323 | { |
324 | P = ElCLib::EllipseValue (U, pos, majorRadius, minorRadius); |
325 | } |
326 | |
327 | //======================================================================= |
328 | //function : D1 |
329 | //purpose : |
330 | //======================================================================= |
331 | |
332 | void Geom2d_Ellipse::D1 (const Standard_Real U, Pnt2d& P, Vec2d& V1) const |
333 | { |
334 | ElCLib::EllipseD1 (U, pos, majorRadius, minorRadius, P, V1); |
335 | } |
336 | |
337 | |
338 | //======================================================================= |
339 | //function : D2 |
340 | //purpose : |
341 | //======================================================================= |
342 | |
343 | void Geom2d_Ellipse::D2 (const Standard_Real U, |
344 | Pnt2d& P, |
345 | Vec2d& V1, Vec2d& V2) const |
346 | { |
347 | ElCLib::EllipseD2 (U, pos, majorRadius, minorRadius, P, V1, V2); |
348 | } |
349 | |
350 | |
351 | //======================================================================= |
352 | //function : D3 |
353 | //purpose : |
354 | //======================================================================= |
355 | |
356 | void Geom2d_Ellipse::D3 (const Standard_Real U, |
357 | Pnt2d& P, |
358 | Vec2d& V1, Vec2d& V2, Vec2d& V3) const |
359 | { |
360 | ElCLib::EllipseD3 (U, pos, majorRadius, minorRadius, P, V1, V2, V3); |
361 | } |
362 | |
363 | |
364 | //======================================================================= |
365 | //function : DN |
366 | //purpose : |
367 | //======================================================================= |
368 | |
369 | Vec2d Geom2d_Ellipse::DN (const Standard_Real U, const Standard_Integer N) const |
370 | { |
371 | Standard_RangeError_Raise_if (N < 1, " "); |
372 | return ElCLib::EllipseDN (U, pos, majorRadius, minorRadius, N); |
373 | } |
374 | |
375 | //======================================================================= |
376 | //function : Transform |
377 | //purpose : |
378 | //======================================================================= |
379 | |
380 | void Geom2d_Ellipse::Transform (const Trsf2d& T) |
381 | { |
382 | majorRadius = majorRadius * Abs(T.ScaleFactor()); |
383 | minorRadius = minorRadius * Abs(T.ScaleFactor()); |
384 | pos.Transform(T); |
385 | } |
bc73b006 |
386 | |
387 | //======================================================================= |
388 | //function : DumpJson |
389 | //purpose : |
390 | //======================================================================= |
391 | void Geom2d_Ellipse::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
392 | { |
393 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
394 | |
395 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Geom2d_Conic) |
396 | |
397 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, majorRadius) |
398 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, minorRadius) |
399 | } |