b311480e |
1 | // Created on: 1993-03-24 |
2 | // Created by: JCV |
3 | // Copyright (c) 1993-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
7fd59977 |
22 | |
23 | |
24 | #include <Geom2d_Ellipse.ixx> |
25 | #include <gp.hxx> |
26 | #include <gp_Dir2d.hxx> |
27 | #include <gp_XYZ.hxx> |
28 | #include <ElCLib.hxx> |
29 | #include <Standard_RangeError.hxx> |
30 | #include <Standard_ConstructionError.hxx> |
31 | |
32 | |
33 | typedef Geom2d_Ellipse Ellipse; |
34 | typedef Handle(Geom2d_Ellipse) Handle(Ellipse); |
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 | |
42 | |
43 | |
44 | |
45 | |
46 | //======================================================================= |
47 | //function : Copy |
48 | //purpose : |
49 | //======================================================================= |
50 | |
51 | Handle(Geom2d_Geometry) Geom2d_Ellipse::Copy() const |
52 | { |
53 | Handle(Ellipse) E; |
54 | E = new Ellipse (pos, majorRadius, minorRadius); |
55 | return E; |
56 | } |
57 | |
58 | |
59 | //======================================================================= |
60 | //function : Geom2d_Ellipse |
61 | //purpose : |
62 | //======================================================================= |
63 | |
64 | Geom2d_Ellipse::Geom2d_Ellipse (const gp_Elips2d& E) { |
65 | |
66 | majorRadius = E.MajorRadius(); |
67 | minorRadius = E.MinorRadius(); |
68 | pos = E.Axis(); |
69 | } |
70 | |
71 | |
72 | |
73 | //======================================================================= |
74 | //function : Geom2d_Ellipse |
75 | //purpose : |
76 | //======================================================================= |
77 | |
78 | Geom2d_Ellipse::Geom2d_Ellipse (const Ax2d& MajorAxis, |
79 | const Standard_Real MajorRadius, |
80 | const Standard_Real MinorRadius, |
81 | const Standard_Boolean Sense) |
82 | :majorRadius (MajorRadius), minorRadius (MinorRadius){ |
83 | |
84 | if (MajorRadius < MinorRadius || MinorRadius < 0.0 ) { |
85 | Standard_ConstructionError::Raise(); |
86 | } |
87 | pos = gp_Ax22d(MajorAxis, Sense); |
88 | } |
89 | |
90 | |
91 | //======================================================================= |
92 | //function : Geom2d_Ellipse |
93 | //purpose : |
94 | //======================================================================= |
95 | |
96 | Geom2d_Ellipse::Geom2d_Ellipse (const gp_Ax22d& Axis, |
97 | const Standard_Real MajorRadius, |
98 | const Standard_Real MinorRadius) |
99 | : majorRadius (MajorRadius), minorRadius (MinorRadius) |
100 | { |
101 | if (MajorRadius < MinorRadius || MinorRadius < 0.0 ) { |
102 | Standard_ConstructionError::Raise(); |
103 | } |
104 | pos = Axis; |
105 | } |
106 | |
107 | |
108 | //======================================================================= |
109 | //function : SetElips2d |
110 | //purpose : |
111 | //======================================================================= |
112 | |
113 | void Geom2d_Ellipse::SetElips2d (const gp_Elips2d& E) |
114 | { |
115 | majorRadius = E.MajorRadius(); |
116 | minorRadius = E.MinorRadius(); |
117 | pos = E.Axis(); |
118 | } |
119 | |
120 | |
121 | //======================================================================= |
122 | //function : SetMajorRadius |
123 | //purpose : |
124 | //======================================================================= |
125 | |
126 | void Geom2d_Ellipse::SetMajorRadius (const Standard_Real MajorRadius) |
127 | { |
128 | if (MajorRadius < minorRadius) |
129 | Standard_ConstructionError::Raise(); |
130 | else |
131 | majorRadius = MajorRadius; |
132 | } |
133 | |
134 | |
135 | //======================================================================= |
136 | //function : SetMinorRadius |
137 | //purpose : |
138 | //======================================================================= |
139 | |
140 | void Geom2d_Ellipse::SetMinorRadius (const Standard_Real MinorRadius) |
141 | { |
142 | if (MinorRadius < 0 || majorRadius < MinorRadius) |
143 | { Standard_ConstructionError::Raise(); } |
144 | else |
145 | { minorRadius = MinorRadius; } |
146 | } |
147 | |
148 | |
149 | //======================================================================= |
150 | //function : Elips2d |
151 | //purpose : |
152 | //======================================================================= |
153 | |
154 | gp_Elips2d Geom2d_Ellipse::Elips2d () const |
155 | { |
156 | return gp_Elips2d (pos, majorRadius, minorRadius); |
157 | } |
158 | |
159 | //======================================================================= |
160 | //function : ReversedParameter |
161 | //purpose : |
162 | //======================================================================= |
163 | |
164 | Standard_Real Geom2d_Ellipse::ReversedParameter( const Standard_Real U) const |
165 | { |
c6541a0c |
166 | return (2. * M_PI - U); |
7fd59977 |
167 | } |
168 | |
169 | //======================================================================= |
170 | //function : Directrix1 |
171 | //purpose : |
172 | //======================================================================= |
173 | |
174 | Ax2d Geom2d_Ellipse::Directrix1 () const |
175 | { |
176 | gp_Elips2d Ev (pos, majorRadius, minorRadius); |
177 | return Ev.Directrix1(); |
178 | } |
179 | |
180 | |
181 | //======================================================================= |
182 | //function : Directrix2 |
183 | //purpose : |
184 | //======================================================================= |
185 | |
186 | Ax2d Geom2d_Ellipse::Directrix2 () const |
187 | { |
188 | gp_Elips2d Ev (pos, majorRadius, minorRadius); |
189 | return Ev.Directrix2(); |
190 | } |
191 | |
192 | |
193 | //======================================================================= |
194 | //function : Eccentricity |
195 | //purpose : |
196 | //======================================================================= |
197 | |
198 | Standard_Real Geom2d_Ellipse::Eccentricity () const |
199 | { |
200 | if (majorRadius == 0.0) |
201 | { return 0.0; } |
202 | else |
203 | { return |
204 | (Sqrt(majorRadius*majorRadius-minorRadius*minorRadius))/majorRadius; |
205 | } |
206 | } |
207 | |
208 | |
209 | //======================================================================= |
210 | //function : Focal |
211 | //purpose : |
212 | //======================================================================= |
213 | |
214 | Standard_Real Geom2d_Ellipse::Focal () const |
215 | { |
216 | return 2.0 * Sqrt(majorRadius * majorRadius - minorRadius * minorRadius); |
217 | } |
218 | |
219 | |
220 | //======================================================================= |
221 | //function : Focus1 |
222 | //purpose : |
223 | //======================================================================= |
224 | |
225 | Pnt2d Geom2d_Ellipse::Focus1 () const |
226 | { |
227 | Standard_Real C = Sqrt(majorRadius * majorRadius - minorRadius * minorRadius); |
228 | return Pnt2d (pos.Location().X() + C * pos.XDirection().X(), |
229 | pos.Location().Y() + C * pos.XDirection().Y()); |
230 | } |
231 | |
232 | |
233 | //======================================================================= |
234 | //function : Focus2 |
235 | //purpose : |
236 | //======================================================================= |
237 | |
238 | Pnt2d Geom2d_Ellipse::Focus2 () const |
239 | { |
240 | Standard_Real C = Sqrt(majorRadius * majorRadius - minorRadius * minorRadius); |
241 | return Pnt2d (pos.Location().X() - C * pos.XDirection().X(), |
242 | pos.Location().Y() - C * pos.XDirection().Y()); |
243 | } |
244 | |
245 | //======================================================================= |
246 | //function : MajorRadius |
247 | //purpose : |
248 | //======================================================================= |
249 | |
250 | Standard_Real Geom2d_Ellipse::MajorRadius () const |
251 | { |
252 | return majorRadius; |
253 | } |
254 | |
255 | //======================================================================= |
256 | //function : MinorRadius |
257 | //purpose : |
258 | //======================================================================= |
259 | |
260 | Standard_Real Geom2d_Ellipse::MinorRadius () const |
261 | { |
262 | return minorRadius; |
263 | } |
264 | |
265 | //======================================================================= |
266 | //function : Parameter |
267 | //purpose : |
268 | //======================================================================= |
269 | |
270 | Standard_Real Geom2d_Ellipse::Parameter () const |
271 | { |
272 | if (majorRadius == 0.0) |
273 | return 0.0; |
274 | else |
275 | return (minorRadius * minorRadius)/majorRadius; |
276 | } |
277 | |
278 | |
279 | //======================================================================= |
280 | //function : FirstParameter |
281 | //purpose : |
282 | //======================================================================= |
283 | |
284 | Standard_Real Geom2d_Ellipse::FirstParameter () const |
285 | { |
286 | return 0.0; |
287 | } |
288 | |
289 | //======================================================================= |
290 | //function : LastParameter |
291 | //purpose : |
292 | //======================================================================= |
293 | |
294 | Standard_Real Geom2d_Ellipse::LastParameter () const |
295 | { |
c6541a0c |
296 | return 2.0 * M_PI; |
7fd59977 |
297 | } |
298 | |
299 | //======================================================================= |
300 | //function : IsClosed |
301 | //purpose : |
302 | //======================================================================= |
303 | |
304 | Standard_Boolean Geom2d_Ellipse::IsClosed () const |
305 | { |
306 | return Standard_True; |
307 | } |
308 | |
309 | //======================================================================= |
310 | //function : IsPeriodic |
311 | //purpose : |
312 | //======================================================================= |
313 | |
314 | Standard_Boolean Geom2d_Ellipse::IsPeriodic () const |
315 | { |
316 | return Standard_True; |
317 | } |
318 | |
319 | //======================================================================= |
320 | //function : D0 |
321 | //purpose : |
322 | //======================================================================= |
323 | |
324 | void Geom2d_Ellipse::D0 (const Standard_Real U, Pnt2d& P) const |
325 | { |
326 | P = ElCLib::EllipseValue (U, pos, majorRadius, minorRadius); |
327 | } |
328 | |
329 | //======================================================================= |
330 | //function : D1 |
331 | //purpose : |
332 | //======================================================================= |
333 | |
334 | void Geom2d_Ellipse::D1 (const Standard_Real U, Pnt2d& P, Vec2d& V1) const |
335 | { |
336 | ElCLib::EllipseD1 (U, pos, majorRadius, minorRadius, P, V1); |
337 | } |
338 | |
339 | |
340 | //======================================================================= |
341 | //function : D2 |
342 | //purpose : |
343 | //======================================================================= |
344 | |
345 | void Geom2d_Ellipse::D2 (const Standard_Real U, |
346 | Pnt2d& P, |
347 | Vec2d& V1, Vec2d& V2) const |
348 | { |
349 | ElCLib::EllipseD2 (U, pos, majorRadius, minorRadius, P, V1, V2); |
350 | } |
351 | |
352 | |
353 | //======================================================================= |
354 | //function : D3 |
355 | //purpose : |
356 | //======================================================================= |
357 | |
358 | void Geom2d_Ellipse::D3 (const Standard_Real U, |
359 | Pnt2d& P, |
360 | Vec2d& V1, Vec2d& V2, Vec2d& V3) const |
361 | { |
362 | ElCLib::EllipseD3 (U, pos, majorRadius, minorRadius, P, V1, V2, V3); |
363 | } |
364 | |
365 | |
366 | //======================================================================= |
367 | //function : DN |
368 | //purpose : |
369 | //======================================================================= |
370 | |
371 | Vec2d Geom2d_Ellipse::DN (const Standard_Real U, const Standard_Integer N) const |
372 | { |
373 | Standard_RangeError_Raise_if (N < 1, " "); |
374 | return ElCLib::EllipseDN (U, pos, majorRadius, minorRadius, N); |
375 | } |
376 | |
377 | //======================================================================= |
378 | //function : Transform |
379 | //purpose : |
380 | //======================================================================= |
381 | |
382 | void Geom2d_Ellipse::Transform (const Trsf2d& T) |
383 | { |
384 | majorRadius = majorRadius * Abs(T.ScaleFactor()); |
385 | minorRadius = minorRadius * Abs(T.ScaleFactor()); |
386 | pos.Transform(T); |
387 | } |