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