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 | |
7fd59977 |
17 | |
7fd59977 |
18 | #include <ElCLib.hxx> |
42cf5bc1 |
19 | #include <Geom2d_Geometry.hxx> |
20 | #include <Geom2d_Hyperbola.hxx> |
21 | #include <gp.hxx> |
22 | #include <gp_Ax2d.hxx> |
23 | #include <gp_Ax22d.hxx> |
7fd59977 |
24 | #include <gp_Dir2d.hxx> |
42cf5bc1 |
25 | #include <gp_Hypr2d.hxx> |
26 | #include <gp_Pnt2d.hxx> |
27 | #include <gp_Trsf2d.hxx> |
28 | #include <gp_Vec2d.hxx> |
7fd59977 |
29 | #include <gp_XY.hxx> |
42cf5bc1 |
30 | #include <Precision.hxx> |
7fd59977 |
31 | #include <Standard_ConstructionError.hxx> |
32 | #include <Standard_DomainError.hxx> |
33 | #include <Standard_RangeError.hxx> |
42cf5bc1 |
34 | #include <Standard_Type.hxx> |
7fd59977 |
35 | |
7fd59977 |
36 | typedef Geom2d_Hyperbola Hyperbola; |
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_Hyperbola::Copy() const |
50 | { |
c04c30b3 |
51 | Handle(Geom2d_Hyperbola) H; |
7fd59977 |
52 | H = new Hyperbola (pos, majorRadius, minorRadius); |
53 | return H; |
54 | } |
55 | |
56 | |
57 | |
58 | //======================================================================= |
59 | //function : Geom2d_Hyperbola |
60 | //purpose : |
61 | //======================================================================= |
62 | |
63 | Geom2d_Hyperbola::Geom2d_Hyperbola (const gp_Hypr2d& H) |
64 | { |
65 | majorRadius = H.MajorRadius(); |
66 | minorRadius = H.MinorRadius(); |
67 | pos = H.Axis(); |
68 | } |
69 | |
70 | |
71 | //======================================================================= |
72 | //function : Geom2d_Hyperbola |
73 | //purpose : |
74 | //======================================================================= |
75 | |
76 | Geom2d_Hyperbola::Geom2d_Hyperbola (const Ax2d& A, |
77 | const Standard_Real MajorRadius, |
78 | const Standard_Real MinorRadius, |
79 | const Standard_Boolean Sense) |
80 | : majorRadius (MajorRadius), minorRadius (MinorRadius) |
81 | { |
82 | if( MajorRadius < 0.0|| MinorRadius < 0.0) |
83 | Standard_ConstructionError::Raise(); |
84 | pos = gp_Ax22d(A, Sense); |
85 | } |
86 | |
87 | //======================================================================= |
88 | //function : Geom2d_Hyperbola |
89 | //purpose : |
90 | //======================================================================= |
91 | |
92 | Geom2d_Hyperbola::Geom2d_Hyperbola (const gp_Ax22d& Axis, |
93 | const Standard_Real MajorRadius, |
94 | const Standard_Real MinorRadius) |
95 | : majorRadius (MajorRadius), minorRadius (MinorRadius) |
96 | { |
97 | if( MajorRadius < 0.0|| MinorRadius < 0.0) |
98 | Standard_ConstructionError::Raise(); |
99 | pos = Axis; |
100 | } |
101 | |
102 | |
103 | //======================================================================= |
104 | //function : SetHypr2d |
105 | //purpose : |
106 | //======================================================================= |
107 | |
108 | void Geom2d_Hyperbola::SetHypr2d (const gp_Hypr2d& H) |
109 | { |
110 | majorRadius = H.MajorRadius(); |
111 | minorRadius = H.MinorRadius(); |
112 | pos = H.Axis(); |
113 | } |
114 | |
115 | |
116 | //======================================================================= |
117 | //function : SetMajorRadius |
118 | //purpose : |
119 | //======================================================================= |
120 | |
121 | void Geom2d_Hyperbola::SetMajorRadius (const Standard_Real MajorRadius) |
122 | { |
123 | if (MajorRadius < 0.0) |
124 | Standard_ConstructionError::Raise(); |
125 | else |
126 | majorRadius = MajorRadius; |
127 | } |
128 | |
129 | |
130 | //======================================================================= |
131 | //function : SetMinorRadius |
132 | //purpose : |
133 | //======================================================================= |
134 | |
135 | void Geom2d_Hyperbola::SetMinorRadius (const Standard_Real MinorRadius) |
136 | { |
137 | if (MinorRadius < 0.0 ) |
138 | Standard_ConstructionError::Raise(); |
139 | else |
140 | minorRadius = MinorRadius; |
141 | } |
142 | |
143 | |
144 | //======================================================================= |
145 | //function : Hypr2d |
146 | //purpose : |
147 | //======================================================================= |
148 | |
149 | gp_Hypr2d Geom2d_Hyperbola::Hypr2d () const |
150 | { |
151 | return gp_Hypr2d (pos, majorRadius, minorRadius); |
152 | } |
153 | |
154 | |
155 | //======================================================================= |
156 | //function : ReversedParameter |
157 | //purpose : |
158 | //======================================================================= |
159 | |
160 | Standard_Real Geom2d_Hyperbola::ReversedParameter( const Standard_Real U) const |
161 | { |
162 | return ( -U); |
163 | } |
164 | |
165 | //======================================================================= |
166 | //function : FirstParameter |
167 | //purpose : |
168 | //======================================================================= |
169 | |
170 | Standard_Real Geom2d_Hyperbola::FirstParameter () const |
171 | { |
172 | return -Precision::Infinite(); |
173 | } |
174 | |
175 | //======================================================================= |
176 | //function : LastParameter |
177 | //purpose : |
178 | //======================================================================= |
179 | |
180 | Standard_Real Geom2d_Hyperbola::LastParameter () const |
181 | { |
182 | return Precision::Infinite(); |
183 | } |
184 | |
185 | //======================================================================= |
186 | //function : IsClosed |
187 | //purpose : |
188 | //======================================================================= |
189 | |
190 | Standard_Boolean Geom2d_Hyperbola::IsClosed () const |
191 | { |
192 | return Standard_False; |
193 | } |
194 | |
195 | //======================================================================= |
196 | //function : IsPeriodic |
197 | //purpose : |
198 | //======================================================================= |
199 | |
200 | Standard_Boolean Geom2d_Hyperbola::IsPeriodic () const |
201 | { |
202 | return Standard_False; |
203 | } |
204 | |
205 | //======================================================================= |
206 | //function : Asymptote1 |
207 | //purpose : |
208 | //======================================================================= |
209 | |
210 | Ax2d Geom2d_Hyperbola::Asymptote1 () const |
211 | { |
212 | gp_Hypr2d Hv (pos, majorRadius, minorRadius); |
213 | return Hv.Asymptote1(); |
214 | } |
215 | |
216 | //======================================================================= |
217 | //function : Asymptote2 |
218 | //purpose : |
219 | //======================================================================= |
220 | |
221 | Ax2d Geom2d_Hyperbola::Asymptote2 () const |
222 | { |
223 | gp_Hypr2d Hv (pos, majorRadius, minorRadius); |
224 | return Hv.Asymptote2(); |
225 | } |
226 | |
227 | //======================================================================= |
228 | //function : ConjugateBranch1 |
229 | //purpose : |
230 | //======================================================================= |
231 | |
232 | gp_Hypr2d Geom2d_Hyperbola::ConjugateBranch1 () const |
233 | { |
234 | gp_Hypr2d Hv (pos, majorRadius, minorRadius); |
235 | return Hv.ConjugateBranch1 (); |
236 | } |
237 | |
238 | //======================================================================= |
239 | //function : ConjugateBranch2 |
240 | //purpose : |
241 | //======================================================================= |
242 | |
243 | gp_Hypr2d Geom2d_Hyperbola::ConjugateBranch2 () const |
244 | { |
245 | gp_Hypr2d Hv (pos, majorRadius, minorRadius); |
246 | return Hv.ConjugateBranch2 (); |
247 | } |
248 | |
249 | //======================================================================= |
250 | //function : Directrix1 |
251 | //purpose : |
252 | //======================================================================= |
253 | |
254 | Ax2d Geom2d_Hyperbola::Directrix1 () const |
255 | { |
256 | gp_Hypr2d Hv (pos, majorRadius, minorRadius); |
257 | return Hv.Directrix1 (); |
258 | } |
259 | |
260 | //======================================================================= |
261 | //function : Directrix2 |
262 | //purpose : |
263 | //======================================================================= |
264 | |
265 | Ax2d Geom2d_Hyperbola::Directrix2 () const |
266 | { |
267 | gp_Hypr2d Hv (pos, majorRadius, minorRadius); |
268 | return Hv.Directrix2 (); |
269 | } |
270 | |
271 | //======================================================================= |
272 | //function : Eccentricity |
273 | //purpose : |
274 | //======================================================================= |
275 | |
276 | Standard_Real Geom2d_Hyperbola::Eccentricity () const |
277 | { |
278 | Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), " "); |
279 | return |
280 | (Sqrt(majorRadius*majorRadius+minorRadius*minorRadius))/majorRadius; |
281 | } |
282 | |
283 | //======================================================================= |
284 | //function : Focal |
285 | //purpose : |
286 | //======================================================================= |
287 | |
288 | Standard_Real Geom2d_Hyperbola::Focal () const |
289 | { |
290 | return 2.0 * Sqrt(majorRadius * majorRadius + minorRadius * minorRadius); |
291 | } |
292 | |
293 | //======================================================================= |
294 | //function : Focus1 |
295 | //purpose : |
296 | //======================================================================= |
297 | |
298 | Pnt2d Geom2d_Hyperbola::Focus1 () const |
299 | { |
300 | Standard_Real C = Sqrt(majorRadius * majorRadius + minorRadius * minorRadius); |
301 | XY Pxy = pos.XDirection().XY(); |
302 | Pxy.Multiply (C); |
303 | Pxy.Add (pos.Location().XY()); |
304 | return Pnt2d (Pxy); |
305 | } |
306 | |
307 | //======================================================================= |
308 | //function : Focus2 |
309 | //purpose : |
310 | //======================================================================= |
311 | |
312 | Pnt2d Geom2d_Hyperbola::Focus2 () const |
313 | { |
314 | Standard_Real C = Sqrt(majorRadius * majorRadius + minorRadius * minorRadius); |
315 | XY Pxy = pos.XDirection().XY(); |
316 | Pxy.Multiply (-C); |
317 | Pxy.Add (pos.Location().XY()); |
318 | return Pnt2d (Pxy); |
319 | } |
320 | |
321 | //======================================================================= |
322 | //function : MajorRadius |
323 | //purpose : |
324 | //======================================================================= |
325 | |
326 | Standard_Real Geom2d_Hyperbola::MajorRadius () const |
327 | { |
328 | return majorRadius; |
329 | } |
330 | |
331 | //======================================================================= |
332 | //function : MinorRadius |
333 | //purpose : |
334 | //======================================================================= |
335 | |
336 | Standard_Real Geom2d_Hyperbola::MinorRadius () const |
337 | { |
338 | return minorRadius; |
339 | } |
340 | |
341 | //======================================================================= |
342 | //function : OtherBranch |
343 | //purpose : |
344 | //======================================================================= |
345 | |
346 | gp_Hypr2d Geom2d_Hyperbola::OtherBranch () const |
347 | { |
348 | gp_Hypr2d Hv (pos, majorRadius, minorRadius); |
349 | return Hv.OtherBranch (); |
350 | } |
351 | |
352 | |
353 | //======================================================================= |
354 | //function : Parameter |
355 | //purpose : |
356 | //======================================================================= |
357 | |
358 | Standard_Real Geom2d_Hyperbola::Parameter () const |
359 | { |
360 | Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), " "); |
361 | return (minorRadius * minorRadius) / majorRadius; |
362 | } |
363 | |
364 | //======================================================================= |
365 | //function : D0 |
366 | //purpose : |
367 | //======================================================================= |
368 | |
369 | void Geom2d_Hyperbola::D0 (const Standard_Real U, |
370 | Pnt2d& P ) const |
371 | { |
372 | P = ElCLib::HyperbolaValue (U, pos, majorRadius, minorRadius); |
373 | } |
374 | |
375 | //======================================================================= |
376 | //function : D1 |
377 | //purpose : |
378 | //======================================================================= |
379 | |
380 | void Geom2d_Hyperbola::D1 (const Standard_Real U, |
381 | Pnt2d& P, |
382 | Vec2d& V1) const |
383 | { |
384 | ElCLib::HyperbolaD1 (U, pos, majorRadius, minorRadius, P, V1); |
385 | } |
386 | |
387 | |
388 | //======================================================================= |
389 | //function : D2 |
390 | //purpose : |
391 | //======================================================================= |
392 | |
393 | void Geom2d_Hyperbola::D2 (const Standard_Real U, |
394 | Pnt2d& P, |
395 | Vec2d& V1, Vec2d& V2) const |
396 | { |
397 | ElCLib::HyperbolaD2 (U, pos, majorRadius, minorRadius, P, V1, V2); |
398 | } |
399 | |
400 | |
401 | //======================================================================= |
402 | //function : D3 |
403 | //purpose : |
404 | //======================================================================= |
405 | |
406 | void Geom2d_Hyperbola::D3 (const Standard_Real U, |
407 | Pnt2d& P, |
408 | Vec2d& V1, Vec2d& V2, Vec2d& V3) const |
409 | { |
410 | ElCLib::HyperbolaD3 (U, pos, majorRadius, minorRadius, P, V1, V2, V3); |
411 | } |
412 | |
413 | |
414 | //======================================================================= |
415 | //function : DN |
416 | //purpose : |
417 | //======================================================================= |
418 | |
419 | Vec2d Geom2d_Hyperbola::DN (const Standard_Real U, const Standard_Integer N) const |
420 | { |
421 | Standard_RangeError_Raise_if (N < 1, " "); |
422 | return ElCLib::HyperbolaDN (U, pos, majorRadius, minorRadius, N); |
423 | } |
424 | |
425 | |
426 | //======================================================================= |
427 | //function : Transform |
428 | //purpose : |
429 | //======================================================================= |
430 | |
431 | void Geom2d_Hyperbola::Transform (const Trsf2d& T) |
432 | { |
433 | majorRadius = majorRadius * Abs (T.ScaleFactor()); |
434 | minorRadius = minorRadius * Abs (T.ScaleFactor()); |
435 | pos.Transform(T); |
436 | } |