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