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