0024023: Revamp the OCCT Handle -- general
[occt.git] / src / Geom / Geom_Hyperbola.cxx
1 // Created on: 1993-03-10
2 // Created by: JCV
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Geom_Hyperbola.ixx>
18
19 #include <Precision.hxx>
20 #include <gp_XYZ.hxx>
21 #include <ElCLib.hxx>
22 #include <Standard_RangeError.hxx>
23 #include <Standard_ConstructionError.hxx>
24
25
26 typedef Geom_Hyperbola         Hyperbola;
27 typedef gp_Ax1  Ax1;
28 typedef gp_Ax2  Ax2;
29 typedef gp_Pnt  Pnt;
30 typedef gp_Vec  Vec;
31 typedef gp_Trsf Trsf;
32 typedef gp_XYZ  XYZ;
33
34 //=======================================================================
35 //function : Copy
36 //purpose  : 
37 //=======================================================================
38
39 Handle(Geom_Geometry) Geom_Hyperbola::Copy() const {
40
41   Handle(Geom_Hyperbola) H;
42   H = new Hyperbola (pos, majorRadius, minorRadius);
43   return H;
44 }
45
46
47
48
49 //=======================================================================
50 //function : Geom_Hyperbola
51 //purpose  : 
52 //=======================================================================
53
54 Geom_Hyperbola::Geom_Hyperbola (const gp_Hypr& H) 
55 : majorRadius (H.MajorRadius()), minorRadius (H.MinorRadius()) {
56
57   pos = H.Position();
58 }
59
60
61 //=======================================================================
62 //function : Geom_Hyperbola
63 //purpose  : 
64 //=======================================================================
65
66 Geom_Hyperbola::Geom_Hyperbola ( const Ax2& A, 
67                                  const Standard_Real MajorRadius, 
68                                  const Standard_Real MinorRadius) 
69  : majorRadius (MajorRadius), minorRadius (MinorRadius) {
70
71   if (MajorRadius < 0.0 || MinorRadius < 0.0) {
72     Standard_ConstructionError::Raise();
73   }
74   pos = A;
75 }
76
77 //=======================================================================
78 //function : IsClosed
79 //purpose  : 
80 //=======================================================================
81
82 Standard_Boolean Geom_Hyperbola::IsClosed () const      { return Standard_False; }
83
84 //=======================================================================
85 //function : IsPeriodic
86 //purpose  : 
87 //=======================================================================
88
89 Standard_Boolean Geom_Hyperbola::IsPeriodic () const    { return Standard_False; } 
90
91 //=======================================================================
92 //function : FirstParameter
93 //purpose  : 
94 //=======================================================================
95
96 Standard_Real Geom_Hyperbola::FirstParameter () const   
97 { return -Precision::Infinite(); }
98
99 //=======================================================================
100 //function : LastParameter
101 //purpose  : 
102 //=======================================================================
103
104 Standard_Real Geom_Hyperbola::LastParameter () const    
105 { return Precision::Infinite(); }
106
107 //=======================================================================
108 //function : MajorRadius
109 //purpose  : 
110 //=======================================================================
111
112 Standard_Real Geom_Hyperbola::MajorRadius () const      { return majorRadius; }
113
114 //=======================================================================
115 //function : MinorRadius
116 //purpose  : 
117 //=======================================================================
118
119 Standard_Real Geom_Hyperbola::MinorRadius () const      { return minorRadius; }
120
121 //=======================================================================
122 //function : SetHypr
123 //purpose  : 
124 //=======================================================================
125
126 void Geom_Hyperbola::SetHypr (const gp_Hypr& H) {
127
128    majorRadius = H.MajorRadius();
129    minorRadius = H.MinorRadius();
130    pos = H.Position();
131 }
132
133
134 //=======================================================================
135 //function : SetMajorRadius
136 //purpose  : 
137 //=======================================================================
138
139 void Geom_Hyperbola::SetMajorRadius (const Standard_Real MajorRadius) {
140
141   if (MajorRadius < 0.0) Standard_ConstructionError::Raise();
142   else                   majorRadius = MajorRadius;
143 }
144
145
146 //=======================================================================
147 //function : SetMinorRadius
148 //purpose  : 
149 //=======================================================================
150
151 void Geom_Hyperbola::SetMinorRadius (const Standard_Real MinorRadius) {
152
153   if (MinorRadius < 0.0)  Standard_ConstructionError::Raise();
154   else                    minorRadius = MinorRadius;
155 }
156
157
158 //=======================================================================
159 //function : Hypr
160 //purpose  : 
161 //=======================================================================
162
163 gp_Hypr Geom_Hyperbola::Hypr () const 
164 {
165   return gp_Hypr (pos, majorRadius, minorRadius);
166 }
167
168 //=======================================================================
169 //function : ReversedParameter
170 //purpose  : 
171 //=======================================================================
172
173 Standard_Real Geom_Hyperbola::ReversedParameter( const Standard_Real U) const 
174 {
175   return ( -U);
176 }
177
178 //=======================================================================
179 //function : Asymptote1
180 //purpose  : 
181 //=======================================================================
182
183 Ax1 Geom_Hyperbola::Asymptote1 () const {
184
185   gp_Hypr Hv (pos, majorRadius, minorRadius);
186   return Hv.Asymptote1();
187 }
188
189
190 //=======================================================================
191 //function : Asymptote2
192 //purpose  : 
193 //=======================================================================
194
195 Ax1 Geom_Hyperbola::Asymptote2 () const {
196
197   gp_Hypr Hv (pos, majorRadius, minorRadius);
198   return Hv.Asymptote2();
199 }
200
201
202 //=======================================================================
203 //function : ConjugateBranch1
204 //purpose  : 
205 //=======================================================================
206
207 gp_Hypr Geom_Hyperbola::ConjugateBranch1 () const {
208
209   gp_Hypr Hv (pos, majorRadius, minorRadius);
210   return Hv.ConjugateBranch1();
211 }
212
213 //=======================================================================
214 //function : ConjugateBranch2
215 //purpose  : 
216 //=======================================================================
217
218 gp_Hypr Geom_Hyperbola::ConjugateBranch2 () const {
219
220   gp_Hypr Hv (pos, majorRadius, minorRadius);
221   return Hv.ConjugateBranch2();
222 }
223
224
225 //=======================================================================
226 //function : Directrix1
227 //purpose  : 
228 //=======================================================================
229
230 Ax1 Geom_Hyperbola::Directrix1 () const {
231
232   gp_Hypr Hv (pos, majorRadius, minorRadius);
233   return Hv.Directrix1();
234 }
235
236 //=======================================================================
237 //function : Directrix2
238 //purpose  : 
239 //=======================================================================
240
241 Ax1 Geom_Hyperbola::Directrix2 () const {
242
243   gp_Hypr Hv (pos, majorRadius, minorRadius);
244   return Hv.Directrix2();
245 }
246
247 //=======================================================================
248 //function : D0
249 //purpose  : 
250 //=======================================================================
251
252 void Geom_Hyperbola::D0 (const Standard_Real U, Pnt& P) const {
253
254   P = ElCLib::HyperbolaValue (U, pos, majorRadius, minorRadius);
255 }
256
257 //=======================================================================
258 //function : D1
259 //purpose  : 
260 //=======================================================================
261
262 void Geom_Hyperbola::D1 (const Standard_Real U, Pnt& P, Vec& V1) const {
263
264   ElCLib::HyperbolaD1 (U, pos, majorRadius, minorRadius, P, V1);
265 }
266
267 //=======================================================================
268 //function : D2
269 //purpose  : 
270 //=======================================================================
271
272 void Geom_Hyperbola::D2 (const Standard_Real U, Pnt& P, Vec& V1, Vec& V2) const {
273
274   ElCLib::HyperbolaD2 (U, pos, majorRadius, minorRadius, P, V1, V2);
275 }
276
277 //=======================================================================
278 //function : D3
279 //purpose  : 
280 //=======================================================================
281
282 void Geom_Hyperbola::D3 (
283 const Standard_Real U, Pnt& P, Vec& V1, Vec& V2, Vec& V3) const {
284
285   ElCLib::HyperbolaD3 (U, pos, majorRadius, minorRadius, P, V1, V2, V3);
286 }
287
288 //=======================================================================
289 //function : DN
290 //purpose  : 
291 //=======================================================================
292
293 Vec Geom_Hyperbola::DN (const Standard_Real U, const Standard_Integer N) const {
294
295   Standard_RangeError_Raise_if (N < 1, " ");  
296   return ElCLib::HyperbolaDN (U, pos, majorRadius, minorRadius, N);
297 }
298
299 //=======================================================================
300 //function : Eccentricity
301 //purpose  : 
302 //=======================================================================
303
304 Standard_Real Geom_Hyperbola::Eccentricity () const {
305
306   Standard_ConstructionError_Raise_if (majorRadius == 0.0, " ")  
307   return (Sqrt(majorRadius*majorRadius + minorRadius*minorRadius))/majorRadius;
308 }
309
310 //=======================================================================
311 //function : Focal
312 //purpose  : 
313 //=======================================================================
314
315 Standard_Real Geom_Hyperbola::Focal () const {
316
317   return 2.0 * Sqrt(majorRadius * majorRadius + minorRadius * minorRadius);
318 }
319
320 //=======================================================================
321 //function : Focus1
322 //purpose  : 
323 //=======================================================================
324
325 Pnt Geom_Hyperbola::Focus1 () const {
326
327   Standard_Real C = Sqrt(majorRadius * majorRadius + minorRadius * minorRadius);
328   Standard_Real Xp, Yp, Zp, Xd, Yd, Zd;
329   pos.Location().Coord (Xp, Yp, Zp);
330   pos.XDirection().Coord (Xd, Yd, Zd);
331   return Pnt (Xp + C * Xd,  Yp + C * Yd, Zp + C * Zd);
332 }
333
334 //=======================================================================
335 //function : Focus2
336 //purpose  : 
337 //=======================================================================
338
339 Pnt Geom_Hyperbola::Focus2 () const {
340
341   Standard_Real C = Sqrt(majorRadius * majorRadius + minorRadius * minorRadius);
342   Standard_Real Xp, Yp, Zp, Xd, Yd, Zd;
343   pos.Location().Coord (Xp, Yp, Zp);
344   pos.XDirection().Coord (Xd, Yd, Zd);
345   return Pnt (Xp - C * Xd,  Yp - C * Yd, Zp - C * Zd);
346 }
347
348 //=======================================================================
349 //function : OtherBranch
350 //purpose  : 
351 //=======================================================================
352
353 gp_Hypr Geom_Hyperbola::OtherBranch () const {
354
355    gp_Hypr Hv (pos, majorRadius, minorRadius);
356    return Hv.OtherBranch ();
357 }
358
359 //=======================================================================
360 //function : Parameter
361 //purpose  : 
362 //=======================================================================
363
364 Standard_Real Geom_Hyperbola::Parameter () const {
365
366    Standard_ConstructionError_Raise_if (majorRadius == 0.0, " ");  
367    return (minorRadius * minorRadius)/majorRadius;
368 }
369
370 //=======================================================================
371 //function : Transform
372 //purpose  : 
373 //=======================================================================
374
375 void Geom_Hyperbola::Transform (const Trsf& T) {
376
377   majorRadius = majorRadius * Abs(T.ScaleFactor());
378   minorRadius = minorRadius * Abs(T.ScaleFactor());
379   pos.Transform(T);
380 }