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