1 // Copyright (c) 1991-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _gp_Dir2d_HeaderFile
16 #define _gp_Dir2d_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.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;
35 //! Describes a unit vector in the plane (2D space). This unit
36 //! vector is also called "Direction".
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
50 //! Creates a direction corresponding to X axis.
53 //! Normalizes the vector V and creates a Direction. Raises ConstructionError if V.Magnitude() <= Resolution from gp.
54 gp_Dir2d(const gp_Vec2d& V);
56 //! Creates a Direction from a doublet of coordinates. Raises ConstructionError if Coord.Modulus() <= Resolution from gp.
57 gp_Dir2d(const gp_XY& Coord);
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);
63 //! For this unit vector, assigns:
65 //! - the X coordinate if Index is 1, or
66 //! - the Y coordinate if Index is 2, and then normalizes it.
68 //! Remember that all the coordinates of a unit vector are
69 //! implicitly modified when any single one is changed directly.
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);
82 //! For this unit vector, assigns:
83 //! - the values Xv and Yv to its two coordinates,
85 //! Remember that all the coordinates of a unit vector are
86 //! implicitly modified when any single one is changed directly.
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);
99 //! Assigns the given value to the X coordinate of this unit vector,
100 //! and then normalizes it.
102 //! Remember that all the coordinates of a unit vector are
103 //! implicitly modified when any single one is changed directly.
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);
114 //! Assigns the given value to the Y coordinate of this unit vector,
115 //! and then normalizes it.
117 //! Remember that all the coordinates of a unit vector are
118 //! implicitly modified when any single one is changed directly.
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);
130 //! - the two coordinates of Coord to this unit vector,
131 //! and then normalizes it.
133 //! Remember that all the coordinates of a unit vector are
134 //! implicitly modified when any single one is changed directly.
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);
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;
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;
155 //! For this unit vector, returns its X coordinate.
156 Standard_Real X() const;
158 //! For this unit vector, returns its Y coordinate.
159 Standard_Real Y() const;
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;
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;
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;
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;
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;
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;
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
201 return Crossed(Right);
204 //! Computes the scalar product
205 Standard_Real Dot (const gp_Dir2d& Other) const;
206 Standard_Real operator * (const gp_Dir2d& Other) const
213 //! Reverses the orientation of a direction
214 Standard_NODISCARD gp_Dir2d Reversed() const;
215 Standard_NODISCARD gp_Dir2d operator -() const
220 Standard_EXPORT void Mirror (const gp_Dir2d& V);
223 //! Performs the symmetrical transformation of a direction
224 //! with respect to the direction V which is the center of
226 Standard_NODISCARD Standard_EXPORT gp_Dir2d Mirrored (const gp_Dir2d& V) const;
228 Standard_EXPORT void Mirror (const gp_Ax2d& A);
231 //! Performs the symmetrical transformation of a direction
232 //! with respect to an axis placement which is the axis
234 Standard_NODISCARD Standard_EXPORT gp_Dir2d Mirrored (const gp_Ax2d& A) const;
236 void Rotate (const Standard_Real Ang);
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;
243 Standard_EXPORT void Transform (const gp_Trsf2d& T);
246 //! Transforms a direction with the "Trsf" T.
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;
271 #include <gp_Dir2d.lxx>
277 #endif // _gp_Dir2d_HeaderFile