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