cc1333dbeeff7668d1beec4e7915422d453c1cd1
[occt.git] / src / gp / gp_Dir2d.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_Dir2d_HeaderFile
16 #define _gp_Dir2d_HeaderFile
17
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
21
22 #include <gp_XY.hxx>
23 #include <Standard_Real.hxx>
24 #include <Standard_Integer.hxx>
25 #include <Standard_Boolean.hxx>
26 class Standard_ConstructionError;
27 class Standard_DomainError;
28 class Standard_OutOfRange;
29 class gp_Vec2d;
30 class gp_XY;
31 class gp_Ax2d;
32 class gp_Trsf2d;
33
34
35 //! Describes a unit vector in the plane (2D space). This unit
36 //! vector is also called "Direction".
37 //! See Also
38 //! gce_MakeDir2d which provides functions for more
39 //! complex unit vector constructions
40 //! Geom2d_Direction which provides additional functions
41 //! for constructing unit vectors and works, in particular, with
42 //! the parametric equations of unit vectors
43 class gp_Dir2d 
44 {
45 public:
46
47   DEFINE_STANDARD_ALLOC
48
49   
50   //! Creates a direction corresponding to X axis.
51     gp_Dir2d();
52   
53   //! Normalizes the vector V and creates a Direction. Raises ConstructionError if V.Magnitude() <= Resolution from gp.
54     gp_Dir2d(const gp_Vec2d& V);
55   
56   //! Creates a Direction from a doublet of coordinates. Raises ConstructionError if Coord.Modulus() <= Resolution from gp.
57     gp_Dir2d(const gp_XY& Coord);
58   
59   //! Creates a Direction with its 2 cartesian coordinates. Raises ConstructionError if Sqrt(Xv*Xv + Yv*Yv) <= Resolution from gp.
60     gp_Dir2d(const Standard_Real Xv, const Standard_Real Yv);
61   
62
63   //! For this unit vector, assigns:
64   //! the value Xi to:
65   //! -   the X coordinate if Index is 1, or
66   //! -   the Y coordinate if Index is 2, and then normalizes it.
67   //! Warning
68   //! Remember that all the coordinates of a unit vector are
69   //! implicitly modified when any single one is changed directly.
70   //! Exceptions
71   //! Standard_OutOfRange if Index is not 1 or 2.
72   //! Standard_ConstructionError if either of the following
73   //! is less than or equal to gp::Resolution():
74   //! -   Sqrt(Xv*Xv + Yv*Yv), or
75   //! -   the modulus of the number pair formed by the new
76   //! value Xi and the other coordinate of this vector that
77   //! was not directly modified.
78   //! Raises OutOfRange if Index != {1, 2}.
79     void SetCoord (const Standard_Integer Index, const Standard_Real Xi);
80   
81
82   //! For this unit vector, assigns:
83   //! -   the values Xv and Yv to its two coordinates,
84   //! Warning
85   //! Remember that all the coordinates of a unit vector are
86   //! implicitly modified when any single one is changed directly.
87   //! Exceptions
88   //! Standard_OutOfRange if Index is not 1 or 2.
89   //! Standard_ConstructionError if either of the following
90   //! is less than or equal to gp::Resolution():
91   //! -   Sqrt(Xv*Xv + Yv*Yv), or
92   //! -   the modulus of the number pair formed by the new
93   //! value Xi and the other coordinate of this vector that
94   //! was not directly modified.
95   //! Raises OutOfRange if Index != {1, 2}.
96     void SetCoord (const Standard_Real Xv, const Standard_Real Yv);
97   
98
99   //! Assigns the given value to the X coordinate of this unit   vector,
100   //! and then normalizes it.
101   //! Warning
102   //! Remember that all the coordinates of a unit vector are
103   //! implicitly modified when any single one is changed directly.
104   //! Exceptions
105   //! Standard_ConstructionError if either of the following
106   //! is less than or equal to gp::Resolution():
107   //! -   the modulus of Coord, or
108   //! -   the modulus of the number pair formed from the new
109   //! X or Y coordinate and the other coordinate of this
110   //! vector that was not directly modified.
111     void SetX (const Standard_Real X);
112   
113
114   //! Assigns  the given value to the Y coordinate of this unit   vector,
115   //! and then normalizes it.
116   //! Warning
117   //! Remember that all the coordinates of a unit vector are
118   //! implicitly modified when any single one is changed directly.
119   //! Exceptions
120   //! Standard_ConstructionError if either of the following
121   //! is less than or equal to gp::Resolution():
122   //! -   the modulus of Coord, or
123   //! -   the modulus of the number pair formed from the new
124   //! X or Y coordinate and the other coordinate of this
125   //! vector that was not directly modified.
126     void SetY (const Standard_Real Y);
127   
128
129   //! Assigns:
130   //! -   the two coordinates of Coord to this unit vector,
131   //! and then normalizes it.
132   //! Warning
133   //! Remember that all the coordinates of a unit vector are
134   //! implicitly modified when any single one is changed directly.
135   //! Exceptions
136   //! Standard_ConstructionError if either of the following
137   //! is less than or equal to gp::Resolution():
138   //! -   the modulus of Coord, or
139   //! -   the modulus of the number pair formed from the new
140   //! X or Y coordinate and the other coordinate of this
141   //! vector that was not directly modified.
142     void SetXY (const gp_XY& Coord);
143   
144
145   //! For this unit vector returns the coordinate of range Index :
146   //! Index = 1 => X is returned
147   //! Index = 2 => Y is returned
148   //! Raises OutOfRange if Index != {1, 2}.
149     Standard_Real Coord (const Standard_Integer Index) const;
150   
151   //! For this unit vector returns its two coordinates Xv and Yv.
152   //! Raises OutOfRange if Index != {1, 2}.
153     void Coord (Standard_Real& Xv, Standard_Real& Yv) const;
154   
155   //! For this unit vector, returns its X coordinate.
156     Standard_Real X() const;
157   
158   //! For this unit vector, returns its Y coordinate.
159     Standard_Real Y() const;
160   
161   //! For this unit vector, returns its two coordinates as a number pair.
162   //! Comparison between Directions
163   //! The precision value is an input data.
164     const gp_XY& XY() const;
165   
166
167   //! Returns True if the two vectors have the same direction
168   //! i.e. the angle between this unit vector and the
169   //! unit vector Other is less than or equal to AngularTolerance.
170     Standard_Boolean IsEqual (const gp_Dir2d& Other, const Standard_Real AngularTolerance) const;
171   
172
173   //! Returns True if the angle between this unit vector and the
174   //! unit vector Other is equal to Pi/2 or -Pi/2 (normal)
175   //! i.e. Abs(Abs(<me>.Angle(Other)) - PI/2.) <= AngularTolerance
176     Standard_Boolean IsNormal (const gp_Dir2d& Other, const Standard_Real AngularTolerance) const;
177   
178
179   //! Returns True if the angle between this unit vector and the
180   //! unit vector Other is equal to Pi or -Pi (opposite).
181   //! i.e.  PI - Abs(<me>.Angle(Other)) <= AngularTolerance
182     Standard_Boolean IsOpposite (const gp_Dir2d& Other, const Standard_Real AngularTolerance) const;
183   
184
185   //! returns true if if the angle between this unit vector and unit
186   //! vector Other is equal to 0, Pi or -Pi.
187   //! i.e.  Abs(Angle(<me>, Other)) <= AngularTolerance or
188   //! PI - Abs(Angle(<me>, Other)) <= AngularTolerance
189     Standard_Boolean IsParallel (const gp_Dir2d& Other, const Standard_Real AngularTolerance) const;
190   
191
192   //! Computes the angular value in radians between <me> and
193   //! <Other>. Returns the angle in the range [-PI, PI].
194   Standard_EXPORT Standard_Real Angle (const gp_Dir2d& Other) const;
195   
196
197   //! Computes the cross product between two directions.
198   Standard_NODISCARD Standard_Real Crossed (const gp_Dir2d& Right) const;
199   Standard_NODISCARD Standard_Real operator ^ (const gp_Dir2d& Right) const
200 {
201   return Crossed(Right);
202 }
203   
204   //! Computes the scalar product
205     Standard_Real Dot (const gp_Dir2d& Other) const;
206   Standard_Real operator * (const gp_Dir2d& Other) const
207 {
208   return Dot(Other);
209 }
210   
211     void Reverse();
212   
213   //! Reverses the orientation of a direction
214     Standard_NODISCARD gp_Dir2d Reversed() const;
215   Standard_NODISCARD gp_Dir2d operator -() const
216 {
217   return Reversed();
218 }
219   
220   Standard_EXPORT void Mirror (const gp_Dir2d& V);
221   
222
223   //! Performs the symmetrical transformation of a direction
224   //! with respect to the direction V which is the center of
225   //! the  symmetry.
226   Standard_EXPORT Standard_NODISCARD gp_Dir2d Mirrored (const gp_Dir2d& V) const;
227   
228   Standard_EXPORT void Mirror (const gp_Ax2d& A);
229   
230
231   //! Performs the symmetrical transformation of a direction
232   //! with respect to an axis placement which is the axis
233   //! of the symmetry.
234   Standard_EXPORT Standard_NODISCARD gp_Dir2d Mirrored (const gp_Ax2d& A) const;
235   
236     void Rotate (const Standard_Real Ang);
237   
238
239   //! Rotates a direction.  Ang is the angular value of
240   //! the rotation in radians.
241     Standard_NODISCARD gp_Dir2d Rotated (const Standard_Real Ang) const;
242   
243   Standard_EXPORT void Transform (const gp_Trsf2d& T);
244   
245
246   //! Transforms a direction with the "Trsf" T.
247   //! Warnings :
248   //! If the scale factor of the "Trsf" T is negative then the
249   //! direction <me> is reversed.
250   Standard_NODISCARD gp_Dir2d Transformed (const gp_Trsf2d& T) const;
251
252
253
254
255 protected:
256
257
258
259
260
261 private:
262
263
264
265   gp_XY coord;
266
267
268 };
269
270
271 #include <gp_Dir2d.lxx>
272
273
274
275
276
277 #endif // _gp_Dir2d_HeaderFile