0024023: Revamp the OCCT Handle -- general
[occt.git] / src / Geom / Geom_Ellipse.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
17#include <Geom_Ellipse.ixx>
18#include <gp_XYZ.hxx>
19#include <ElCLib.hxx>
20#include <Standard_ConstructionError.hxx>
21#include <Standard_RangeError.hxx>
22
23typedef Geom_Ellipse Ellipse;
7fd59977 24typedef gp_Ax1 Ax1;
25typedef gp_Ax2 Ax2;
26typedef gp_Pnt Pnt;
27typedef gp_Vec Vec;
28typedef gp_Trsf Trsf;
29typedef gp_XYZ XYZ;
30
7fd59977 31//=======================================================================
32//function : Copy
33//purpose :
34//=======================================================================
35
36Handle(Geom_Geometry) Geom_Ellipse::Copy() const
37{
c04c30b3 38 Handle(Geom_Ellipse) E;
7fd59977 39 E = new Ellipse (pos, majorRadius, minorRadius);
40 return E;
41}
42
43
44
45
46//=======================================================================
47//function : Geom_Ellipse
48//purpose :
49//=======================================================================
50
51Geom_Ellipse::Geom_Ellipse (const gp_Elips& E)
52 : majorRadius (E.MajorRadius()), minorRadius (E.MinorRadius())
53{
54 pos = E.Position ();
55}
56
57
58//=======================================================================
59//function : Geom_Ellipse
60//purpose :
61//=======================================================================
62
63Geom_Ellipse::Geom_Ellipse ( const Ax2& A,
64 const Standard_Real MajorRadius,
65 const Standard_Real MinorRadius)
66 : majorRadius (MajorRadius), minorRadius (MinorRadius) {
67
68 if (MajorRadius < MinorRadius || MinorRadius < 0.0 ) {
69 Standard_ConstructionError::Raise();
70 }
71 pos = A;
72}
73
74
75//=======================================================================
76//function : IsClosed
77//purpose :
78//=======================================================================
79
80Standard_Boolean Geom_Ellipse::IsClosed () const { return Standard_True; }
81
82//=======================================================================
83//function : IsPeriodic
84//purpose :
85//=======================================================================
86
87Standard_Boolean Geom_Ellipse::IsPeriodic () const { return Standard_True; }
88
89//=======================================================================
90//function : FirstParameter
91//purpose :
92//=======================================================================
93
94Standard_Real Geom_Ellipse::FirstParameter () const { return 0.0; }
95
96//=======================================================================
97//function : LastParameter
98//purpose :
99//=======================================================================
100
c6541a0c 101Standard_Real Geom_Ellipse::LastParameter () const { return 2.0 * M_PI; }
7fd59977 102
103//=======================================================================
104//function : MajorRadius
105//purpose :
106//=======================================================================
107
108Standard_Real Geom_Ellipse::MajorRadius () const { return majorRadius; }
109
110//=======================================================================
111//function : MinorRadius
112//purpose :
113//=======================================================================
114
115Standard_Real Geom_Ellipse::MinorRadius () const { return minorRadius; }
116
117//=======================================================================
118//function : SetElips
119//purpose :
120//=======================================================================
121
122void Geom_Ellipse::SetElips (const gp_Elips& E) {
123
124 majorRadius = E.MajorRadius();
125 minorRadius = E.MinorRadius();
126 pos = E.Position();
127}
128
129
130//=======================================================================
131//function : SetMajorRadius
132//purpose :
133//=======================================================================
134
135void Geom_Ellipse::SetMajorRadius (const Standard_Real MajorRadius) {
136
137 if (MajorRadius < minorRadius) Standard_ConstructionError::Raise ();
138 else majorRadius = MajorRadius;
139}
140
141
142//=======================================================================
143//function : SetMinorRadius
144//purpose :
145//=======================================================================
146
147void Geom_Ellipse::SetMinorRadius (const Standard_Real MinorRadius) {
148
149 if (MinorRadius < 0 || majorRadius < MinorRadius) {
150 Standard_ConstructionError::Raise();
151 }
152 else { minorRadius = MinorRadius; }
153}
154
155
156//=======================================================================
157//function : Elips
158//purpose :
159//=======================================================================
160
161gp_Elips Geom_Ellipse::Elips () const {
162
163 return gp_Elips (pos, majorRadius, minorRadius);
164}
165
166
167//=======================================================================
168//function : ReversedParameter
169//purpose :
170//=======================================================================
171
172Standard_Real Geom_Ellipse::ReversedParameter( const Standard_Real U) const
173{
c6541a0c 174 return ( 2. * M_PI - U);
7fd59977 175}
176
177
178//=======================================================================
179//function : Directrix1
180//purpose :
181//=======================================================================
182
183Ax1 Geom_Ellipse::Directrix1 () const {
184
185 gp_Elips Ev (pos, majorRadius, minorRadius);
186 return Ev.Directrix1();
187}
188
189
190//=======================================================================
191//function : Directrix2
192//purpose :
193//=======================================================================
194
195Ax1 Geom_Ellipse::Directrix2 () const {
196
197 gp_Elips Ev (pos, majorRadius, minorRadius);
198 return Ev.Directrix2();
199}
200
201
202//=======================================================================
203//function : D0
204//purpose :
205//=======================================================================
206
207void Geom_Ellipse::D0 (const Standard_Real U, gp_Pnt& P) const {
208
209 P = ElCLib::EllipseValue (U, pos, majorRadius, minorRadius);
210}
211
212
213//=======================================================================
214//function : D1
215//purpose :
216//=======================================================================
217
218void Geom_Ellipse::D1 (const Standard_Real U, Pnt& P, Vec& V1) const {
219
220 ElCLib::EllipseD1 (U, pos, majorRadius, minorRadius, P, V1);
221}
222
223
224//=======================================================================
225//function : D2
226//purpose :
227//=======================================================================
228
229void Geom_Ellipse::D2 (const Standard_Real U, Pnt& P, Vec& V1, Vec& V2) const {
230
231 ElCLib::EllipseD2 (U, pos, majorRadius, minorRadius, P, V1, V2);
232}
233
234
235//=======================================================================
236//function : D3
237//purpose :
238//=======================================================================
239
240void Geom_Ellipse::D3 (const Standard_Real U, Pnt& P, Vec& V1, Vec& V2, Vec& V3) const {
241
242 ElCLib::EllipseD3 (U, pos, majorRadius, minorRadius, P, V1, V2, V3);
243}
244
245
246//=======================================================================
247//function : DN
248//purpose :
249//=======================================================================
250
251Vec Geom_Ellipse::DN (const Standard_Real U, const Standard_Integer N) const {
252
253 Standard_RangeError_Raise_if (N < 1, " ");
254 return ElCLib::EllipseDN (U, pos, majorRadius, minorRadius, N);
255}
256
257
258//=======================================================================
259//function : Eccentricity
260//purpose :
261//=======================================================================
262
263Standard_Real Geom_Ellipse::Eccentricity () const {
264
265 if (majorRadius == 0.0) { return 0.0; }
266 else {
267 return (Sqrt(majorRadius*majorRadius-minorRadius*minorRadius))/majorRadius;
268 }
269}
270
271
272//=======================================================================
273//function : Focal
274//purpose :
275//=======================================================================
276
277Standard_Real Geom_Ellipse::Focal () const {
278
279 return 2.0 * Sqrt(majorRadius * majorRadius - minorRadius * minorRadius);
280}
281
282
283//=======================================================================
284//function : Focus1
285//purpose :
286//=======================================================================
287
288Pnt Geom_Ellipse::Focus1 () const {
289
290 Standard_Real C = Sqrt (majorRadius * majorRadius - minorRadius * minorRadius);
291 Standard_Real Xp, Yp, Zp, Xd, Yd, Zd;
292 pos.Location().Coord (Xp, Yp, Zp);
293 pos.XDirection().Coord (Xd, Yd, Zd);
294 return Pnt (Xp + C * Xd, Yp + C * Yd, Zp + C * Zd);
295}
296
297
298//=======================================================================
299//function : Focus2
300//purpose :
301//=======================================================================
302
303Pnt Geom_Ellipse::Focus2 () const {
304
305 Standard_Real C = Sqrt (majorRadius * majorRadius - minorRadius * minorRadius);
306 Standard_Real Xp, Yp, Zp, Xd, Yd, Zd;
307 pos.Location().Coord (Xp, Yp, Zp);
308 pos.XDirection().Coord (Xd, Yd, Zd);
309 return Pnt (Xp - C * Xd, Yp - C * Yd, Zp - C * Zd);
310}
311
312
313//=======================================================================
314//function : Parameter
315//purpose :
316//=======================================================================
317
318Standard_Real Geom_Ellipse::Parameter () const {
319
320 if (majorRadius == 0.0) return 0.0;
321 else return (minorRadius * minorRadius) / majorRadius;
322}
323
324
325//=======================================================================
326//function : Transform
327//purpose :
328//=======================================================================
329
330void Geom_Ellipse::Transform (const Trsf& T) {
331
332 majorRadius = majorRadius * Abs(T.ScaleFactor());
333 minorRadius = minorRadius * Abs(T.ScaleFactor());
334 pos.Transform(T);
335}