0a1dc0566074cd63e19392e642c3ae53f4a7e785
[occt.git] / src / gp / gp_Elips2d.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_Elips2d_HeaderFile
16 #define _gp_Elips2d_HeaderFile
17
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
21
22 #include <gp_Ax22d.hxx>
23 #include <Standard_Real.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <gp_Ax2d.hxx>
26 #include <gp_Pnt2d.hxx>
27 class Standard_ConstructionError;
28 class gp_Ax2d;
29 class gp_Ax22d;
30 class gp_Pnt2d;
31 class gp_Trsf2d;
32 class gp_Vec2d;
33
34
35
36 //! Describes an ellipse in the plane (2D space).
37 //! An ellipse is defined by its major and minor radii and
38 //! positioned in the plane with a coordinate system (a
39 //! gp_Ax22d object) as follows:
40 //! -   the origin of the coordinate system is the center of the ellipse,
41 //! -   its "X Direction" defines the major axis of the ellipse, and
42 //! -   its "Y Direction" defines the minor axis of the ellipse.
43 //! This coordinate system is the "local coordinate system"
44 //! of the ellipse. Its orientation (direct or indirect) gives an
45 //! implicit orientation to the ellipse. In this coordinate
46 //! system, the equation of the ellipse is:
47 //! @code
48 //! X*X / (MajorRadius**2) + Y*Y / (MinorRadius**2) = 1.0
49 //! @endcode
50 //! See Also
51 //! gce_MakeElips2d which provides functions for more
52 //! complex ellipse constructions
53 //! Geom2d_Ellipse which provides additional functions for
54 //! constructing ellipses and works, in particular, with the
55 //! parametric equations of ellipses
56 class gp_Elips2d 
57 {
58 public:
59
60   DEFINE_STANDARD_ALLOC
61
62   
63   //! Creates an indefinite ellipse.
64     gp_Elips2d();
65   
66
67   //! Creates an ellipse with the major axis, the major and the
68   //! minor radius. The location of the MajorAxis is the center
69   //! of the  ellipse.
70   //! The sense of parametrization is given by Sense.
71   //! Warnings :
72   //! It is possible to create an ellipse with
73   //! MajorRadius = MinorRadius.
74   //! Raises ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.0
75     gp_Elips2d(const gp_Ax2d& MajorAxis, const Standard_Real MajorRadius, const Standard_Real MinorRadius, const Standard_Boolean Sense = Standard_True);
76   
77   //! Creates an ellipse with radii MajorRadius and
78   //! MinorRadius, positioned in the plane by coordinate system A where:
79   //! -   the origin of A is the center of the ellipse,
80   //! -   the "X Direction" of A defines the major axis of
81   //! the ellipse, that is, the major radius MajorRadius
82   //! is measured along this axis, and
83   //! -   the "Y Direction" of A defines the minor axis of
84   //! the ellipse, that is, the minor radius MinorRadius
85   //! is measured along this axis, and
86   //! -   the orientation (direct or indirect sense) of A
87   //! gives the orientation of the ellipse.
88   //! Warnings :
89   //! It is possible to create an ellipse with
90   //! MajorRadius = MinorRadius.
91   //! Raises ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.0
92   gp_Elips2d(const gp_Ax22d& A, const Standard_Real MajorRadius, const Standard_Real MinorRadius);
93   
94   //! Modifies this ellipse, by redefining its local coordinate system so that
95   //! -   its origin becomes P.
96   void SetLocation (const gp_Pnt2d& P);
97   
98   //! Changes the value of the major radius.
99   //! Raises ConstructionError if MajorRadius < MinorRadius.
100   void SetMajorRadius (const Standard_Real MajorRadius);
101   
102   //! Changes the value of the minor radius.
103   //! Raises ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.0
104   void SetMinorRadius (const Standard_Real MinorRadius);
105   
106   //! Modifies this ellipse, by redefining its local coordinate system so that
107   //! it becomes A.
108   void SetAxis (const gp_Ax22d& A);
109   
110   //! Modifies this ellipse, by redefining its local coordinate system so that
111   //! its origin and its "X Direction"  become those
112   //! of the axis A. The "Y  Direction"  is then
113   //! recomputed. The orientation of the local coordinate
114   //! system is not modified.
115   void SetXAxis (const gp_Ax2d& A);
116   
117   //! Modifies this ellipse, by redefining its local coordinate system so that
118   //! its origin and its "Y Direction"  become those
119   //! of the axis A. The "X  Direction"  is then
120   //! recomputed. The orientation of the local coordinate
121   //! system is not modified.
122   void SetYAxis (const gp_Ax2d& A);
123   
124   //! Computes the area of the ellipse.
125     Standard_Real Area() const;
126   
127
128   //! Returns the coefficients of the implicit equation of the ellipse.
129   //! A * (X**2) + B * (Y**2) + 2*C*(X*Y) + 2*D*X + 2*E*Y + F = 0.
130   Standard_EXPORT void Coefficients (Standard_Real& A, Standard_Real& B, Standard_Real& C, Standard_Real& D, Standard_Real& E, Standard_Real& F) const;
131   
132
133   //! This directrix is the line normal to the XAxis of the ellipse
134   //! in the local plane (Z = 0) at a distance d = MajorRadius / e
135   //! from the center of the ellipse, where e is the eccentricity of
136   //! the ellipse.
137   //! This line is parallel to the "YAxis". The intersection point
138   //! between directrix1 and the "XAxis" is the location point of the
139   //! directrix1. This point is on the positive side of the "XAxis".
140   //!
141   //! Raised if Eccentricity = 0.0. (The ellipse degenerates into a
142   //! circle)
143     gp_Ax2d Directrix1() const;
144   
145
146   //! This line is obtained by the symmetrical transformation
147   //! of "Directrix1" with respect to the minor axis of the ellipse.
148   //!
149   //! Raised if Eccentricity = 0.0. (The ellipse degenerates into a
150   //! circle).
151     gp_Ax2d Directrix2() const;
152   
153
154   //! Returns the eccentricity of the ellipse  between 0.0 and 1.0
155   //! If f is the distance between the center of the ellipse and
156   //! the Focus1 then the eccentricity e = f / MajorRadius.
157   //! Returns 0 if MajorRadius = 0.
158     Standard_Real Eccentricity() const;
159   
160
161   //! Returns the distance between the center of the ellipse
162   //! and focus1 or focus2.
163     Standard_Real Focal() const;
164   
165
166   //! Returns the first focus of the ellipse. This focus is on the
167   //! positive side of the major axis of the ellipse.
168     gp_Pnt2d Focus1() const;
169   
170
171   //! Returns the second focus of the ellipse. This focus is on the
172   //! negative side of the major axis of the ellipse.
173     gp_Pnt2d Focus2() const;
174   
175   //! Returns the center of the ellipse.
176     const gp_Pnt2d& Location() const;
177   
178   //! Returns the major radius of the Ellipse.
179     Standard_Real MajorRadius() const;
180   
181   //! Returns the minor radius of the Ellipse.
182     Standard_Real MinorRadius() const;
183   
184
185   //! Returns p = (1 - e * e) * MajorRadius where e is the eccentricity
186   //! of the ellipse.
187   //! Returns 0 if MajorRadius = 0
188     Standard_Real Parameter() const;
189   
190   //! Returns the major axis of the ellipse.
191     const gp_Ax22d& Axis() const;
192   
193   //! Returns the major axis of the ellipse.
194     gp_Ax2d XAxis() const;
195   
196   //! Returns the minor axis of the ellipse.
197   //! Reverses the direction of the circle.
198     gp_Ax2d YAxis() const;
199   
200     void Reverse();
201   
202     Standard_NODISCARD gp_Elips2d Reversed() const;
203   
204   //! Returns true if the local coordinate system is direct
205   //! and false in the other case.
206     Standard_Boolean IsDirect() const;
207   
208   Standard_EXPORT void Mirror (const gp_Pnt2d& P);
209   
210
211   //! Performs the symmetrical transformation of a ellipse with respect
212   //! to the point P which is the center of the symmetry
213   Standard_NODISCARD Standard_EXPORT gp_Elips2d Mirrored (const gp_Pnt2d& P) const;
214   
215   Standard_EXPORT void Mirror (const gp_Ax2d& A);
216   
217
218   //! Performs the symmetrical transformation of a ellipse with respect
219   //! to an axis placement which is the axis of the symmetry.
220   Standard_NODISCARD Standard_EXPORT gp_Elips2d Mirrored (const gp_Ax2d& A) const;
221   
222   void Rotate (const gp_Pnt2d& P, const Standard_Real Ang);
223   
224   Standard_NODISCARD gp_Elips2d Rotated (const gp_Pnt2d& P, const Standard_Real Ang) const;
225   
226   void Scale (const gp_Pnt2d& P, const Standard_Real S);
227   
228
229   //! Scales a ellipse. S is the scaling value.
230   Standard_NODISCARD gp_Elips2d Scaled (const gp_Pnt2d& P, const Standard_Real S) const;
231   
232   void Transform (const gp_Trsf2d& T);
233   
234
235   //! Transforms an ellipse with the transformation T from class Trsf2d.
236   Standard_NODISCARD gp_Elips2d Transformed (const gp_Trsf2d& T) const;
237   
238   void Translate (const gp_Vec2d& V);
239   
240
241   //! Translates a ellipse in the direction of the vector V.
242   //! The magnitude of the translation is the vector's magnitude.
243   Standard_NODISCARD gp_Elips2d Translated (const gp_Vec2d& V) const;
244   
245   void Translate (const gp_Pnt2d& P1, const gp_Pnt2d& P2);
246   
247
248   //! Translates a ellipse from the point P1 to the point P2.
249   Standard_NODISCARD gp_Elips2d Translated (const gp_Pnt2d& P1, const gp_Pnt2d& P2) const;
250
251
252
253
254 protected:
255
256
257
258
259
260 private:
261
262
263
264   gp_Ax22d pos;
265   Standard_Real majorRadius;
266   Standard_Real minorRadius;
267
268
269 };
270
271
272 #include <gp_Elips2d.lxx>
273
274
275
276
277
278 #endif // _gp_Elips2d_HeaderFile