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 | |
7fd59977 |
34 | typedef Geom2d_Ellipse Ellipse; |
7fd59977 |
35 | typedef gp_Ax2d Ax2d; |
36 | typedef gp_Dir2d Dir2d; |
37 | typedef gp_Pnt2d Pnt2d; |
38 | typedef gp_Vec2d Vec2d; |
39 | typedef gp_Trsf2d Trsf2d; |
40 | typedef gp_XY XY; |
41 | |
7fd59977 |
42 | //======================================================================= |
43 | //function : Copy |
44 | //purpose : |
45 | //======================================================================= |
46 | |
47 | Handle(Geom2d_Geometry) Geom2d_Ellipse::Copy() const |
48 | { |
c04c30b3 |
49 | Handle(Geom2d_Ellipse) E; |
7fd59977 |
50 | E = new Ellipse (pos, majorRadius, minorRadius); |
51 | return E; |
52 | } |
53 | |
54 | |
55 | //======================================================================= |
56 | //function : Geom2d_Ellipse |
57 | //purpose : |
58 | //======================================================================= |
59 | |
60 | Geom2d_Ellipse::Geom2d_Ellipse (const gp_Elips2d& E) { |
61 | |
62 | majorRadius = E.MajorRadius(); |
63 | minorRadius = E.MinorRadius(); |
64 | pos = E.Axis(); |
65 | } |
66 | |
67 | |
68 | |
69 | //======================================================================= |
70 | //function : Geom2d_Ellipse |
71 | //purpose : |
72 | //======================================================================= |
73 | |
74 | Geom2d_Ellipse::Geom2d_Ellipse (const Ax2d& MajorAxis, |
75 | const Standard_Real MajorRadius, |
76 | const Standard_Real MinorRadius, |
77 | const Standard_Boolean Sense) |
78 | :majorRadius (MajorRadius), minorRadius (MinorRadius){ |
79 | |
80 | if (MajorRadius < MinorRadius || MinorRadius < 0.0 ) { |
81 | Standard_ConstructionError::Raise(); |
82 | } |
83 | pos = gp_Ax22d(MajorAxis, Sense); |
84 | } |
85 | |
86 | |
87 | //======================================================================= |
88 | //function : Geom2d_Ellipse |
89 | //purpose : |
90 | //======================================================================= |
91 | |
92 | Geom2d_Ellipse::Geom2d_Ellipse (const gp_Ax22d& Axis, |
93 | const Standard_Real MajorRadius, |
94 | const Standard_Real MinorRadius) |
95 | : majorRadius (MajorRadius), minorRadius (MinorRadius) |
96 | { |
97 | if (MajorRadius < MinorRadius || MinorRadius < 0.0 ) { |
98 | Standard_ConstructionError::Raise(); |
99 | } |
100 | pos = Axis; |
101 | } |
102 | |
103 | |
104 | //======================================================================= |
105 | //function : SetElips2d |
106 | //purpose : |
107 | //======================================================================= |
108 | |
109 | void Geom2d_Ellipse::SetElips2d (const gp_Elips2d& E) |
110 | { |
111 | majorRadius = E.MajorRadius(); |
112 | minorRadius = E.MinorRadius(); |
113 | pos = E.Axis(); |
114 | } |
115 | |
116 | |
117 | //======================================================================= |
118 | //function : SetMajorRadius |
119 | //purpose : |
120 | //======================================================================= |
121 | |
122 | void Geom2d_Ellipse::SetMajorRadius (const Standard_Real MajorRadius) |
123 | { |
124 | if (MajorRadius < minorRadius) |
125 | Standard_ConstructionError::Raise(); |
126 | else |
127 | majorRadius = MajorRadius; |
128 | } |
129 | |
130 | |
131 | //======================================================================= |
132 | //function : SetMinorRadius |
133 | //purpose : |
134 | //======================================================================= |
135 | |
136 | void Geom2d_Ellipse::SetMinorRadius (const Standard_Real MinorRadius) |
137 | { |
138 | if (MinorRadius < 0 || majorRadius < MinorRadius) |
139 | { Standard_ConstructionError::Raise(); } |
140 | else |
141 | { minorRadius = MinorRadius; } |
142 | } |
143 | |
144 | |
145 | //======================================================================= |
146 | //function : Elips2d |
147 | //purpose : |
148 | //======================================================================= |
149 | |
150 | gp_Elips2d Geom2d_Ellipse::Elips2d () const |
151 | { |
152 | return gp_Elips2d (pos, majorRadius, minorRadius); |
153 | } |
154 | |
155 | //======================================================================= |
156 | //function : ReversedParameter |
157 | //purpose : |
158 | //======================================================================= |
159 | |
160 | Standard_Real Geom2d_Ellipse::ReversedParameter( const Standard_Real U) const |
161 | { |
c6541a0c |
162 | return (2. * M_PI - U); |
7fd59977 |
163 | } |
164 | |
165 | //======================================================================= |
166 | //function : Directrix1 |
167 | //purpose : |
168 | //======================================================================= |
169 | |
170 | Ax2d Geom2d_Ellipse::Directrix1 () const |
171 | { |
172 | gp_Elips2d Ev (pos, majorRadius, minorRadius); |
173 | return Ev.Directrix1(); |
174 | } |
175 | |
176 | |
177 | //======================================================================= |
178 | //function : Directrix2 |
179 | //purpose : |
180 | //======================================================================= |
181 | |
182 | Ax2d Geom2d_Ellipse::Directrix2 () const |
183 | { |
184 | gp_Elips2d Ev (pos, majorRadius, minorRadius); |
185 | return Ev.Directrix2(); |
186 | } |
187 | |
188 | |
189 | //======================================================================= |
190 | //function : Eccentricity |
191 | //purpose : |
192 | //======================================================================= |
193 | |
194 | Standard_Real Geom2d_Ellipse::Eccentricity () const |
195 | { |
196 | if (majorRadius == 0.0) |
197 | { return 0.0; } |
198 | else |
199 | { return |
200 | (Sqrt(majorRadius*majorRadius-minorRadius*minorRadius))/majorRadius; |
201 | } |
202 | } |
203 | |
204 | |
205 | //======================================================================= |
206 | //function : Focal |
207 | //purpose : |
208 | //======================================================================= |
209 | |
210 | Standard_Real Geom2d_Ellipse::Focal () const |
211 | { |
212 | return 2.0 * Sqrt(majorRadius * majorRadius - minorRadius * minorRadius); |
213 | } |
214 | |
215 | |
216 | //======================================================================= |
217 | //function : Focus1 |
218 | //purpose : |
219 | //======================================================================= |
220 | |
221 | Pnt2d Geom2d_Ellipse::Focus1 () const |
222 | { |
223 | Standard_Real C = Sqrt(majorRadius * majorRadius - minorRadius * minorRadius); |
224 | return Pnt2d (pos.Location().X() + C * pos.XDirection().X(), |
225 | pos.Location().Y() + C * pos.XDirection().Y()); |
226 | } |
227 | |
228 | |
229 | //======================================================================= |
230 | //function : Focus2 |
231 | //purpose : |
232 | //======================================================================= |
233 | |
234 | Pnt2d Geom2d_Ellipse::Focus2 () const |
235 | { |
236 | Standard_Real C = Sqrt(majorRadius * majorRadius - minorRadius * minorRadius); |
237 | return Pnt2d (pos.Location().X() - C * pos.XDirection().X(), |
238 | pos.Location().Y() - C * pos.XDirection().Y()); |
239 | } |
240 | |
241 | //======================================================================= |
242 | //function : MajorRadius |
243 | //purpose : |
244 | //======================================================================= |
245 | |
246 | Standard_Real Geom2d_Ellipse::MajorRadius () const |
247 | { |
248 | return majorRadius; |
249 | } |
250 | |
251 | //======================================================================= |
252 | //function : MinorRadius |
253 | //purpose : |
254 | //======================================================================= |
255 | |
256 | Standard_Real Geom2d_Ellipse::MinorRadius () const |
257 | { |
258 | return minorRadius; |
259 | } |
260 | |
261 | //======================================================================= |
262 | //function : Parameter |
263 | //purpose : |
264 | //======================================================================= |
265 | |
266 | Standard_Real Geom2d_Ellipse::Parameter () const |
267 | { |
268 | if (majorRadius == 0.0) |
269 | return 0.0; |
270 | else |
271 | return (minorRadius * minorRadius)/majorRadius; |
272 | } |
273 | |
274 | |
275 | //======================================================================= |
276 | //function : FirstParameter |
277 | //purpose : |
278 | //======================================================================= |
279 | |
280 | Standard_Real Geom2d_Ellipse::FirstParameter () const |
281 | { |
282 | return 0.0; |
283 | } |
284 | |
285 | //======================================================================= |
286 | //function : LastParameter |
287 | //purpose : |
288 | //======================================================================= |
289 | |
290 | Standard_Real Geom2d_Ellipse::LastParameter () const |
291 | { |
c6541a0c |
292 | return 2.0 * M_PI; |
7fd59977 |
293 | } |
294 | |
295 | //======================================================================= |
296 | //function : IsClosed |
297 | //purpose : |
298 | //======================================================================= |
299 | |
300 | Standard_Boolean Geom2d_Ellipse::IsClosed () const |
301 | { |
302 | return Standard_True; |
303 | } |
304 | |
305 | //======================================================================= |
306 | //function : IsPeriodic |
307 | //purpose : |
308 | //======================================================================= |
309 | |
310 | Standard_Boolean Geom2d_Ellipse::IsPeriodic () const |
311 | { |
312 | return Standard_True; |
313 | } |
314 | |
315 | //======================================================================= |
316 | //function : D0 |
317 | //purpose : |
318 | //======================================================================= |
319 | |
320 | void Geom2d_Ellipse::D0 (const Standard_Real U, Pnt2d& P) const |
321 | { |
322 | P = ElCLib::EllipseValue (U, pos, majorRadius, minorRadius); |
323 | } |
324 | |
325 | //======================================================================= |
326 | //function : D1 |
327 | //purpose : |
328 | //======================================================================= |
329 | |
330 | void Geom2d_Ellipse::D1 (const Standard_Real U, Pnt2d& P, Vec2d& V1) const |
331 | { |
332 | ElCLib::EllipseD1 (U, pos, majorRadius, minorRadius, P, V1); |
333 | } |
334 | |
335 | |
336 | //======================================================================= |
337 | //function : D2 |
338 | //purpose : |
339 | //======================================================================= |
340 | |
341 | void Geom2d_Ellipse::D2 (const Standard_Real U, |
342 | Pnt2d& P, |
343 | Vec2d& V1, Vec2d& V2) const |
344 | { |
345 | ElCLib::EllipseD2 (U, pos, majorRadius, minorRadius, P, V1, V2); |
346 | } |
347 | |
348 | |
349 | //======================================================================= |
350 | //function : D3 |
351 | //purpose : |
352 | //======================================================================= |
353 | |
354 | void Geom2d_Ellipse::D3 (const Standard_Real U, |
355 | Pnt2d& P, |
356 | Vec2d& V1, Vec2d& V2, Vec2d& V3) const |
357 | { |
358 | ElCLib::EllipseD3 (U, pos, majorRadius, minorRadius, P, V1, V2, V3); |
359 | } |
360 | |
361 | |
362 | //======================================================================= |
363 | //function : DN |
364 | //purpose : |
365 | //======================================================================= |
366 | |
367 | Vec2d Geom2d_Ellipse::DN (const Standard_Real U, const Standard_Integer N) const |
368 | { |
369 | Standard_RangeError_Raise_if (N < 1, " "); |
370 | return ElCLib::EllipseDN (U, pos, majorRadius, minorRadius, N); |
371 | } |
372 | |
373 | //======================================================================= |
374 | //function : Transform |
375 | //purpose : |
376 | //======================================================================= |
377 | |
378 | void Geom2d_Ellipse::Transform (const Trsf2d& T) |
379 | { |
380 | majorRadius = majorRadius * Abs(T.ScaleFactor()); |
381 | minorRadius = minorRadius * Abs(T.ScaleFactor()); |
382 | pos.Transform(T); |
383 | } |