b311480e |
1 | // Created on: 1993-03-10 |
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 | |
7fd59977 |
18 | #include <ElCLib.hxx> |
42cf5bc1 |
19 | #include <Geom_Ellipse.hxx> |
20 | #include <Geom_Geometry.hxx> |
21 | #include <gp_Ax1.hxx> |
22 | #include <gp_Ax2.hxx> |
23 | #include <gp_Elips.hxx> |
24 | #include <gp_Pnt.hxx> |
25 | #include <gp_Trsf.hxx> |
26 | #include <gp_Vec.hxx> |
27 | #include <gp_XYZ.hxx> |
7fd59977 |
28 | #include <Standard_ConstructionError.hxx> |
29 | #include <Standard_RangeError.hxx> |
42cf5bc1 |
30 | #include <Standard_Type.hxx> |
7fd59977 |
31 | |
92efcf78 |
32 | IMPLEMENT_STANDARD_RTTIEXT(Geom_Ellipse,Geom_Conic) |
33 | |
7fd59977 |
34 | typedef gp_Ax1 Ax1; |
35 | typedef gp_Ax2 Ax2; |
36 | typedef gp_Pnt Pnt; |
37 | typedef gp_Vec Vec; |
38 | typedef gp_Trsf Trsf; |
39 | typedef gp_XYZ XYZ; |
40 | |
7fd59977 |
41 | //======================================================================= |
42 | //function : Copy |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | Handle(Geom_Geometry) Geom_Ellipse::Copy() const |
47 | { |
c04c30b3 |
48 | Handle(Geom_Ellipse) E; |
896faa72 |
49 | E = new Geom_Ellipse(pos, majorRadius, minorRadius); |
7fd59977 |
50 | return E; |
51 | } |
52 | |
53 | |
54 | |
55 | |
56 | //======================================================================= |
57 | //function : Geom_Ellipse |
58 | //purpose : |
59 | //======================================================================= |
60 | |
61 | Geom_Ellipse::Geom_Ellipse (const gp_Elips& E) |
62 | : majorRadius (E.MajorRadius()), minorRadius (E.MinorRadius()) |
63 | { |
64 | pos = E.Position (); |
65 | } |
66 | |
67 | |
68 | //======================================================================= |
69 | //function : Geom_Ellipse |
70 | //purpose : |
71 | //======================================================================= |
72 | |
73 | Geom_Ellipse::Geom_Ellipse ( const Ax2& A, |
74 | const Standard_Real MajorRadius, |
75 | const Standard_Real MinorRadius) |
76 | : majorRadius (MajorRadius), minorRadius (MinorRadius) { |
77 | |
78 | if (MajorRadius < MinorRadius || MinorRadius < 0.0 ) { |
9775fa61 |
79 | throw Standard_ConstructionError(); |
7fd59977 |
80 | } |
81 | pos = A; |
82 | } |
83 | |
84 | |
85 | //======================================================================= |
86 | //function : IsClosed |
87 | //purpose : |
88 | //======================================================================= |
89 | |
90 | Standard_Boolean Geom_Ellipse::IsClosed () const { return Standard_True; } |
91 | |
92 | //======================================================================= |
93 | //function : IsPeriodic |
94 | //purpose : |
95 | //======================================================================= |
96 | |
97 | Standard_Boolean Geom_Ellipse::IsPeriodic () const { return Standard_True; } |
98 | |
99 | //======================================================================= |
100 | //function : FirstParameter |
101 | //purpose : |
102 | //======================================================================= |
103 | |
104 | Standard_Real Geom_Ellipse::FirstParameter () const { return 0.0; } |
105 | |
106 | //======================================================================= |
107 | //function : LastParameter |
108 | //purpose : |
109 | //======================================================================= |
110 | |
c6541a0c |
111 | Standard_Real Geom_Ellipse::LastParameter () const { return 2.0 * M_PI; } |
7fd59977 |
112 | |
113 | //======================================================================= |
114 | //function : MajorRadius |
115 | //purpose : |
116 | //======================================================================= |
117 | |
118 | Standard_Real Geom_Ellipse::MajorRadius () const { return majorRadius; } |
119 | |
120 | //======================================================================= |
121 | //function : MinorRadius |
122 | //purpose : |
123 | //======================================================================= |
124 | |
125 | Standard_Real Geom_Ellipse::MinorRadius () const { return minorRadius; } |
126 | |
127 | //======================================================================= |
128 | //function : SetElips |
129 | //purpose : |
130 | //======================================================================= |
131 | |
132 | void Geom_Ellipse::SetElips (const gp_Elips& E) { |
133 | |
134 | majorRadius = E.MajorRadius(); |
135 | minorRadius = E.MinorRadius(); |
136 | pos = E.Position(); |
137 | } |
138 | |
139 | |
140 | //======================================================================= |
141 | //function : SetMajorRadius |
142 | //purpose : |
143 | //======================================================================= |
144 | |
145 | void Geom_Ellipse::SetMajorRadius (const Standard_Real MajorRadius) { |
146 | |
9775fa61 |
147 | if (MajorRadius < minorRadius) throw Standard_ConstructionError(); |
7fd59977 |
148 | else majorRadius = MajorRadius; |
149 | } |
150 | |
151 | |
152 | //======================================================================= |
153 | //function : SetMinorRadius |
154 | //purpose : |
155 | //======================================================================= |
156 | |
157 | void Geom_Ellipse::SetMinorRadius (const Standard_Real MinorRadius) { |
158 | |
159 | if (MinorRadius < 0 || majorRadius < MinorRadius) { |
9775fa61 |
160 | throw Standard_ConstructionError(); |
7fd59977 |
161 | } |
162 | else { minorRadius = MinorRadius; } |
163 | } |
164 | |
165 | |
166 | //======================================================================= |
167 | //function : Elips |
168 | //purpose : |
169 | //======================================================================= |
170 | |
171 | gp_Elips Geom_Ellipse::Elips () const { |
172 | |
173 | return gp_Elips (pos, majorRadius, minorRadius); |
174 | } |
175 | |
176 | |
177 | //======================================================================= |
178 | //function : ReversedParameter |
179 | //purpose : |
180 | //======================================================================= |
181 | |
182 | Standard_Real Geom_Ellipse::ReversedParameter( const Standard_Real U) const |
183 | { |
c6541a0c |
184 | return ( 2. * M_PI - U); |
7fd59977 |
185 | } |
186 | |
187 | |
188 | //======================================================================= |
189 | //function : Directrix1 |
190 | //purpose : |
191 | //======================================================================= |
192 | |
193 | Ax1 Geom_Ellipse::Directrix1 () const { |
194 | |
195 | gp_Elips Ev (pos, majorRadius, minorRadius); |
196 | return Ev.Directrix1(); |
197 | } |
198 | |
199 | |
200 | //======================================================================= |
201 | //function : Directrix2 |
202 | //purpose : |
203 | //======================================================================= |
204 | |
205 | Ax1 Geom_Ellipse::Directrix2 () const { |
206 | |
207 | gp_Elips Ev (pos, majorRadius, minorRadius); |
208 | return Ev.Directrix2(); |
209 | } |
210 | |
211 | |
212 | //======================================================================= |
213 | //function : D0 |
214 | //purpose : |
215 | //======================================================================= |
216 | |
217 | void Geom_Ellipse::D0 (const Standard_Real U, gp_Pnt& P) const { |
218 | |
219 | P = ElCLib::EllipseValue (U, pos, majorRadius, minorRadius); |
220 | } |
221 | |
222 | |
223 | //======================================================================= |
224 | //function : D1 |
225 | //purpose : |
226 | //======================================================================= |
227 | |
228 | void Geom_Ellipse::D1 (const Standard_Real U, Pnt& P, Vec& V1) const { |
229 | |
230 | ElCLib::EllipseD1 (U, pos, majorRadius, minorRadius, P, V1); |
231 | } |
232 | |
233 | |
234 | //======================================================================= |
235 | //function : D2 |
236 | //purpose : |
237 | //======================================================================= |
238 | |
239 | void Geom_Ellipse::D2 (const Standard_Real U, Pnt& P, Vec& V1, Vec& V2) const { |
240 | |
241 | ElCLib::EllipseD2 (U, pos, majorRadius, minorRadius, P, V1, V2); |
242 | } |
243 | |
244 | |
245 | //======================================================================= |
246 | //function : D3 |
247 | //purpose : |
248 | //======================================================================= |
249 | |
250 | void Geom_Ellipse::D3 (const Standard_Real U, Pnt& P, Vec& V1, Vec& V2, Vec& V3) const { |
251 | |
252 | ElCLib::EllipseD3 (U, pos, majorRadius, minorRadius, P, V1, V2, V3); |
253 | } |
254 | |
255 | |
256 | //======================================================================= |
257 | //function : DN |
258 | //purpose : |
259 | //======================================================================= |
260 | |
261 | Vec Geom_Ellipse::DN (const Standard_Real U, const Standard_Integer N) const { |
262 | |
263 | Standard_RangeError_Raise_if (N < 1, " "); |
264 | return ElCLib::EllipseDN (U, pos, majorRadius, minorRadius, N); |
265 | } |
266 | |
267 | |
268 | //======================================================================= |
269 | //function : Eccentricity |
270 | //purpose : |
271 | //======================================================================= |
272 | |
273 | Standard_Real Geom_Ellipse::Eccentricity () const { |
274 | |
275 | if (majorRadius == 0.0) { return 0.0; } |
276 | else { |
277 | return (Sqrt(majorRadius*majorRadius-minorRadius*minorRadius))/majorRadius; |
278 | } |
279 | } |
280 | |
281 | |
282 | //======================================================================= |
283 | //function : Focal |
284 | //purpose : |
285 | //======================================================================= |
286 | |
287 | Standard_Real Geom_Ellipse::Focal () const { |
288 | |
289 | return 2.0 * Sqrt(majorRadius * majorRadius - minorRadius * minorRadius); |
290 | } |
291 | |
292 | |
293 | //======================================================================= |
294 | //function : Focus1 |
295 | //purpose : |
296 | //======================================================================= |
297 | |
298 | Pnt Geom_Ellipse::Focus1 () const { |
299 | |
300 | Standard_Real C = Sqrt (majorRadius * majorRadius - minorRadius * minorRadius); |
301 | Standard_Real Xp, Yp, Zp, Xd, Yd, Zd; |
302 | pos.Location().Coord (Xp, Yp, Zp); |
303 | pos.XDirection().Coord (Xd, Yd, Zd); |
304 | return Pnt (Xp + C * Xd, Yp + C * Yd, Zp + C * Zd); |
305 | } |
306 | |
307 | |
308 | //======================================================================= |
309 | //function : Focus2 |
310 | //purpose : |
311 | //======================================================================= |
312 | |
313 | Pnt Geom_Ellipse::Focus2 () const { |
314 | |
315 | Standard_Real C = Sqrt (majorRadius * majorRadius - minorRadius * minorRadius); |
316 | Standard_Real Xp, Yp, Zp, Xd, Yd, Zd; |
317 | pos.Location().Coord (Xp, Yp, Zp); |
318 | pos.XDirection().Coord (Xd, Yd, Zd); |
319 | return Pnt (Xp - C * Xd, Yp - C * Yd, Zp - C * Zd); |
320 | } |
321 | |
322 | |
323 | //======================================================================= |
324 | //function : Parameter |
325 | //purpose : |
326 | //======================================================================= |
327 | |
328 | Standard_Real Geom_Ellipse::Parameter () const { |
329 | |
330 | if (majorRadius == 0.0) return 0.0; |
331 | else return (minorRadius * minorRadius) / majorRadius; |
332 | } |
333 | |
334 | |
335 | //======================================================================= |
336 | //function : Transform |
337 | //purpose : |
338 | //======================================================================= |
339 | |
340 | void Geom_Ellipse::Transform (const Trsf& T) { |
341 | |
342 | majorRadius = majorRadius * Abs(T.ScaleFactor()); |
343 | minorRadius = minorRadius * Abs(T.ScaleFactor()); |
344 | pos.Transform(T); |
345 | } |
bc73b006 |
346 | |
347 | //======================================================================= |
348 | //function : DumpJson |
349 | //purpose : |
350 | //======================================================================= |
351 | void Geom_Ellipse::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
352 | { |
353 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
354 | |
355 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Geom_Conic) |
356 | |
357 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, majorRadius) |
358 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, minorRadius) |
359 | } |