56df6f3ade8aab364c4324e670112096edeaab61
[occt.git] / src / gp / gp_Elips.hxx
1 // Copyright (c) 1991-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _gp_Elips_HeaderFile
16 #define _gp_Elips_HeaderFile
17
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
21
22 #include <gp_Ax2.hxx>
23 #include <Standard_Real.hxx>
24 #include <gp_Ax1.hxx>
25 #include <gp_Pnt.hxx>
26 class Standard_ConstructionError;
27 class gp_Ax2;
28 class gp_Ax1;
29 class gp_Pnt;
30 class gp_Trsf;
31 class gp_Vec;
32
33
34
35 //! Describes an ellipse in 3D space.
36 //! An ellipse is defined by its major and minor radii and
37 //! positioned in space with a coordinate system (a gp_Ax2 object) as follows:
38 //! -   the origin of the coordinate system is the center of the ellipse,
39 //! -   its "X Direction" defines the major axis of the ellipse, and
40 //! - its "Y Direction" defines the minor axis of the ellipse.
41 //! Together, the origin, "X Direction" and "Y Direction" of
42 //! this coordinate system define the plane of the ellipse.
43 //! This coordinate system is the "local coordinate system"
44 //! of the ellipse. In this coordinate system, the equation of
45 //! the ellipse is:
46 //! X*X / (MajorRadius**2) + Y*Y / (MinorRadius**2) = 1.0
47 //! The "main Direction" of the local coordinate system gives
48 //! the normal vector to the plane of the ellipse. This vector
49 //! gives an implicit orientation to the ellipse (definition of the
50 //! trigonometric sense). We refer to the "main Axis" of the
51 //! local coordinate system as the "Axis" of the ellipse.
52 //! See Also
53 //! gce_MakeElips which provides functions for more
54 //! complex ellipse constructions
55 //! Geom_Ellipse which provides additional functions for
56 //! constructing ellipses and works, in particular, with the
57 //! parametric equations of ellipses
58 class gp_Elips 
59 {
60 public:
61
62   DEFINE_STANDARD_ALLOC
63
64   
65   //! Creates an indefinite ellipse.
66     gp_Elips();
67   
68
69   //! The major radius of the ellipse is on the "XAxis" and the
70   //! minor radius is on the "YAxis" of the ellipse. The "XAxis"
71   //! is defined with the "XDirection" of A2 and the "YAxis" is
72   //! defined with the "YDirection" of A2.
73   //! Warnings :
74   //! It is not forbidden to create an ellipse with MajorRadius =
75   //! MinorRadius.
76   //! Raises ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.
77     gp_Elips(const gp_Ax2& A2, const Standard_Real MajorRadius, const Standard_Real MinorRadius);
78   
79
80   //! Changes the axis normal to the plane of the ellipse.
81   //! It modifies the definition of this plane.
82   //! The "XAxis" and the "YAxis" are recomputed.
83   //! The local coordinate system is redefined so that:
84   //! -   its origin and "main Direction" become those of the
85   //! axis A1 (the "X Direction" and "Y Direction" are then
86   //! recomputed in the same way as for any gp_Ax2), or
87   //! Raises ConstructionError if the direction of A1
88   //! is parallel to the direction of the "XAxis" of the ellipse.
89     void SetAxis (const gp_Ax1& A1);
90   
91   //! Modifies this ellipse, by redefining its local coordinate
92   //! so that its origin becomes P.
93     void SetLocation (const gp_Pnt& P);
94   
95
96   //! The major radius of the ellipse is on the "XAxis" (major axis)
97   //! of the ellipse.
98   //! Raises ConstructionError if MajorRadius < MinorRadius.
99     void SetMajorRadius (const Standard_Real MajorRadius);
100   
101
102   //! The minor radius of the ellipse is on the "YAxis" (minor axis)
103   //! of the ellipse.
104   //! Raises ConstructionError if MinorRadius > MajorRadius or MinorRadius < 0.
105     void SetMinorRadius (const Standard_Real MinorRadius);
106   
107   //! Modifies this ellipse, by redefining its local coordinate
108   //! so that it becomes A2e.
109     void SetPosition (const gp_Ax2& A2);
110   
111   //! Computes the area of the Ellipse.
112     Standard_Real Area() const;
113   
114
115   //! Computes the axis normal to the plane of the ellipse.
116     const gp_Ax1& Axis() const;
117   
118   //! Computes the first or second directrix of this ellipse.
119   //! These are the lines, in the plane of the ellipse, normal to
120   //! the major axis, at a distance equal to
121   //! MajorRadius/e from the center of the ellipse, where
122   //! e is the eccentricity of the ellipse.
123   //! The first directrix (Directrix1) is on the positive side of
124   //! the major axis. The second directrix (Directrix2) is on
125   //! the negative side.
126   //! The directrix is returned as an axis (gp_Ax1 object), the
127   //! origin of which is situated on the "X Axis" of the local
128   //! coordinate system of this ellipse.
129   //! Exceptions
130   //! Standard_ConstructionError if the eccentricity is null
131   //! (the ellipse has degenerated into a circle).
132     gp_Ax1 Directrix1() const;
133   
134
135   //! This line is obtained by the symmetrical transformation
136   //! of "Directrix1" with respect to the "YAxis" of the ellipse.
137   //! Exceptions
138   //! Standard_ConstructionError if the eccentricity is null
139   //! (the ellipse has degenerated into a circle).
140     gp_Ax1 Directrix2() const;
141   
142
143   //! Returns the eccentricity of the ellipse  between 0.0 and 1.0
144   //! If f is the distance between the center of the ellipse and
145   //! the Focus1 then the eccentricity e = f / MajorRadius.
146   //! Raises ConstructionError if MajorRadius = 0.0
147     Standard_Real Eccentricity() const;
148   
149
150   //! Computes the focal distance. It is the distance between the
151   //! two focus focus1 and focus2 of the ellipse.
152     Standard_Real Focal() const;
153   
154
155   //! Returns the first focus of the ellipse. This focus is on the
156   //! positive side of the "XAxis" of the ellipse.
157     gp_Pnt Focus1() const;
158   
159
160   //! Returns the second focus of the ellipse. This focus is on the
161   //! negative side of the "XAxis" of the ellipse.
162     gp_Pnt Focus2() const;
163   
164
165   //! Returns the center of the ellipse. It is the "Location"
166   //! point of the coordinate system of the ellipse.
167     const gp_Pnt& Location() const;
168   
169   //! Returns the major radius of the ellipse.
170     Standard_Real MajorRadius() const;
171   
172   //! Returns the minor radius of the ellipse.
173     Standard_Real MinorRadius() const;
174   
175
176   //! Returns p = (1 - e * e) * MajorRadius where e is the eccentricity
177   //! of the ellipse.
178   //! Returns 0 if MajorRadius = 0
179     Standard_Real Parameter() const;
180   
181   //! Returns the coordinate system of the ellipse.
182     const gp_Ax2& Position() const;
183   
184
185   //! Returns the "XAxis" of the ellipse whose origin
186   //! is the center of this ellipse. It is the major axis of the
187   //! ellipse.
188     gp_Ax1 XAxis() const;
189   
190
191   //! Returns the "YAxis" of the ellipse whose unit vector is the "X Direction" or the "Y Direction"
192   //! of the local coordinate system of this ellipse.
193   //! This is the minor axis of the ellipse.
194     gp_Ax1 YAxis() const;
195   
196   Standard_EXPORT void Mirror (const gp_Pnt& P);
197   
198
199   //! Performs the symmetrical transformation of an ellipse with
200   //! respect to the point P which is the center of the symmetry.
201   Standard_EXPORT Standard_NODISCARD gp_Elips Mirrored (const gp_Pnt& P) const;
202   
203   Standard_EXPORT void Mirror (const gp_Ax1& A1);
204   
205
206   //! Performs the symmetrical transformation of an ellipse with
207   //! respect to an axis placement which is the axis of the symmetry.
208   Standard_EXPORT Standard_NODISCARD gp_Elips Mirrored (const gp_Ax1& A1) const;
209   
210   Standard_EXPORT void Mirror (const gp_Ax2& A2);
211   
212
213   //! Performs the symmetrical transformation of an ellipse with
214   //! respect to a plane. The axis placement A2 locates the plane
215   //! of the symmetry (Location, XDirection, YDirection).
216   Standard_EXPORT Standard_NODISCARD gp_Elips Mirrored (const gp_Ax2& A2) const;
217   
218     void Rotate (const gp_Ax1& A1, const Standard_Real Ang);
219   
220
221   //! Rotates an ellipse. A1 is the axis of the rotation.
222   //! Ang is the angular value of the rotation in radians.
223     Standard_NODISCARD gp_Elips Rotated (const gp_Ax1& A1, const Standard_Real Ang) const;
224   
225     void Scale (const gp_Pnt& P, const Standard_Real S);
226   
227
228   //! Scales an ellipse. S is the scaling value.
229     Standard_NODISCARD gp_Elips Scaled (const gp_Pnt& P, const Standard_Real S) const;
230   
231     void Transform (const gp_Trsf& T);
232   
233
234   //! Transforms an ellipse with the transformation T from class Trsf.
235     Standard_NODISCARD gp_Elips Transformed (const gp_Trsf& T) const;
236   
237     void Translate (const gp_Vec& V);
238   
239
240   //! Translates an ellipse in the direction of the vector V.
241   //! The magnitude of the translation is the vector's magnitude.
242     Standard_NODISCARD gp_Elips Translated (const gp_Vec& V) const;
243   
244     void Translate (const gp_Pnt& P1, const gp_Pnt& P2);
245   
246
247   //! Translates an ellipse from the point P1 to the point P2.
248     Standard_NODISCARD gp_Elips Translated (const gp_Pnt& P1, const gp_Pnt& P2) const;
249
250
251
252
253 protected:
254
255
256
257
258
259 private:
260
261
262
263   gp_Ax2 pos;
264   Standard_Real majorRadius;
265   Standard_Real minorRadius;
266
267
268 };
269
270
271 #include <gp_Elips.lxx>
272
273
274
275
276
277 #endif // _gp_Elips_HeaderFile