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_Ax2d_HeaderFile
16 #define _gp_Ax2d_HeaderFile
17 
18 #include <gp_Pnt2d.hxx>
19 #include <gp_Dir2d.hxx>
20 
21 class gp_Trsf2d;
22 class gp_Vec2d;
23 
24 //! Describes an axis in the plane (2D space).
25 //! An axis is defined by:
26 //! -   its origin (also referred to as its "Location point"),   and
27 //! -   its unit vector (referred to as its "Direction").
28 //! An axis implicitly defines a direct, right-handed
29 //! coordinate system in 2D space by:
30 //! -   its origin,
31 //! - its "Direction" (giving the "X Direction" of the coordinate system), and
32 //! -   the unit vector normal to "Direction" (positive angle
33 //! measured in the trigonometric sense).
34 //! An axis is used:
35 //! -   to describe 2D geometric entities (for example, the
36 //! axis which defines angular coordinates on a circle).
37 //! It serves for the same purpose as the STEP function
38 //! "axis placement one axis", or
39 //! -   to define geometric transformations (axis of
40 //! symmetry, axis of rotation, and so on).
41 //! Note: to define a left-handed 2D coordinate system, use gp_Ax22d.
42 class gp_Ax2d
43 {
44 public:
45 
46   DEFINE_STANDARD_ALLOC
47 
48   //! Creates an axis object representing X axis of the reference co-ordinate system.
gp_Ax2d()49   gp_Ax2d() : loc(0.,0.)
50   //vdir(1.,0.) use default ctor of gp_Dir2d, as it creates the same dir (1,0)
51   {}
52 
53   //! Creates an Ax2d.
54   //! <theP> is the "Location" point of the axis placement
55   //! and theV is the "Direction" of the axis placement.
gp_Ax2d(const gp_Pnt2d & theP,const gp_Dir2d & theV)56   gp_Ax2d (const gp_Pnt2d& theP, const gp_Dir2d& theV)
57   : loc (theP),
58     vdir (theV)
59   {}
60 
61   //! Changes the "Location" point (origin) of <me>.
SetLocation(const gp_Pnt2d & theP)62   void SetLocation (const gp_Pnt2d& theP) { loc = theP; }
63 
64   //! Changes the direction of <me>.
SetDirection(const gp_Dir2d & theV)65   void SetDirection (const gp_Dir2d& theV) { vdir = theV; }
66 
67   //! Returns the origin of <me>.
Location() const68   const gp_Pnt2d& Location() const { return loc; }
69 
70   //! Returns the direction of <me>.
Direction() const71   const gp_Dir2d& Direction() const { return vdir; }
72 
73   //! Returns True if  :
74   //! . the angle between <me> and <Other> is lower or equal
75   //! to <AngularTolerance> and
76   //! . the distance between <me>.Location() and <Other> is lower
77   //! or equal to <LinearTolerance> and
78   //! . the distance between <Other>.Location() and <me> is lower
79   //! or equal to LinearTolerance.
80   Standard_EXPORT Standard_Boolean IsCoaxial (const gp_Ax2d& Other, const Standard_Real AngularTolerance, const Standard_Real LinearTolerance) const;
81 
82   //! Returns true if this axis and the axis theOther are normal to each other.
83   //! That is, if the angle between the two axes is equal to Pi/2 or -Pi/2.
84   //! Note: the tolerance criterion is given by theAngularTolerance.
IsNormal(const gp_Ax2d & theOther,const Standard_Real theAngularTolerance) const85   Standard_Boolean IsNormal (const gp_Ax2d& theOther, const Standard_Real theAngularTolerance) const
86   {
87     return vdir.IsNormal (theOther.vdir, theAngularTolerance);
88   }
89 
90   //! Returns true if this axis and the axis theOther are parallel, and have opposite orientations.
91   //! That is, if the angle between the two axes is equal to Pi or -Pi.
92   //! Note: the tolerance criterion is given by theAngularTolerance.
IsOpposite(const gp_Ax2d & theOther,const Standard_Real theAngularTolerance) const93   Standard_Boolean IsOpposite (const gp_Ax2d& theOther, const Standard_Real theAngularTolerance) const
94   {
95     return vdir.IsOpposite (theOther.vdir, theAngularTolerance);
96   }
97 
98   //! Returns true if this axis and the axis theOther are parallel,
99   //! and have either the same or opposite orientations.
100   //! That is, if the angle between the two axes is equal to 0, Pi or -Pi.
101   //! Note: the tolerance criterion is given by theAngularTolerance.
IsParallel(const gp_Ax2d & theOther,const Standard_Real theAngularTolerance) const102   Standard_Boolean IsParallel (const gp_Ax2d& theOther, const Standard_Real theAngularTolerance) const
103   {
104     return vdir.IsParallel (theOther.vdir, theAngularTolerance);
105   }
106 
107   //! Computes the angle, in radians, between this axis and the axis theOther.
108   //! The value of the angle is between -Pi and Pi.
Angle(const gp_Ax2d & theOther) const109   Standard_Real Angle (const gp_Ax2d& theOther) const { return vdir.Angle (theOther.vdir); }
110 
111   //! Reverses the direction of <me> and assigns the result to this axis.
Reverse()112   void Reverse() { vdir.Reverse(); }
113 
114   //! Computes a new axis placement with a direction opposite to the direction of <me>.
Reversed() const115   Standard_NODISCARD gp_Ax2d Reversed() const
116   {
117     gp_Ax2d aTemp = *this;
118     aTemp.Reverse();
119     return aTemp;
120   }
121 
122   Standard_EXPORT void Mirror (const gp_Pnt2d& P);
123 
124   //! Performs the symmetrical transformation of an axis
125   //! placement with respect to the point P which is the
126   //! center of the symmetry.
127   Standard_NODISCARD Standard_EXPORT gp_Ax2d Mirrored (const gp_Pnt2d& P) const;
128 
129   Standard_EXPORT void Mirror (const gp_Ax2d& A);
130 
131   //! Performs the symmetrical transformation of an axis
132   //! placement with respect to an axis placement which
133   //! is the axis of the symmetry.
134   Standard_NODISCARD Standard_EXPORT gp_Ax2d Mirrored (const gp_Ax2d& A) const;
135 
Rotate(const gp_Pnt2d & theP,const Standard_Real theAng)136   void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng)
137   {
138     loc.Rotate (theP, theAng);
139     vdir.Rotate (theAng);
140   }
141 
142   //! Rotates an axis placement. <theP> is the center of the rotation.
143   //! theAng is the angular value of the rotation in radians.
Rotated(const gp_Pnt2d & theP,const Standard_Real theAng) const144   Standard_NODISCARD gp_Ax2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const
145   {
146     gp_Ax2d anA = *this;
147     anA.Rotate (theP, theAng);
148     return anA;
149   }
150 
151   Standard_EXPORT void Scale (const gp_Pnt2d& P, const Standard_Real S);
152 
153   //! Applies a scaling transformation on the axis placement.
154   //! The "Location" point of the axisplacement is modified.
155   //! The "Direction" is reversed if the scale is negative.
Scaled(const gp_Pnt2d & theP,const Standard_Real theS) const156   Standard_NODISCARD gp_Ax2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const
157   {
158     gp_Ax2d anA = *this;
159     anA.Scale (theP, theS);
160     return anA;
161   }
162 
Transform(const gp_Trsf2d & theT)163   void Transform (const gp_Trsf2d& theT)
164   {
165     loc .Transform (theT);
166     vdir.Transform (theT);
167   }
168 
169   //! Transforms an axis placement with a Trsf.
Transformed(const gp_Trsf2d & theT) const170   Standard_NODISCARD gp_Ax2d Transformed (const gp_Trsf2d& theT) const
171   {
172     gp_Ax2d anA = *this;
173     anA.Transform (theT);
174     return anA;
175   }
176 
Translate(const gp_Vec2d & theV)177   void Translate (const gp_Vec2d& theV) { loc.Translate (theV); }
178 
179   //! Translates an axis placement in the direction of the vector theV.
180   //! The magnitude of the translation is the vector's magnitude.
Translated(const gp_Vec2d & theV) const181   Standard_NODISCARD gp_Ax2d Translated (const gp_Vec2d& theV) const
182   {
183     gp_Ax2d anA = *this;
184     (anA.loc).Translate (theV);
185     return anA;
186   }
187 
Translate(const gp_Pnt2d & theP1,const gp_Pnt2d & theP2)188   void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { loc.Translate (theP1, theP2); }
189 
190   //! Translates an axis placement from the point theP1 to the point theP2.
Translated(const gp_Pnt2d & theP1,const gp_Pnt2d & theP2) const191   Standard_NODISCARD gp_Ax2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const
192   {
193     gp_Ax2d anA = *this;
194     (anA.loc).Translate (gp_Vec2d (theP1, theP2));
195     return anA;
196   }
197 
198   //! Dumps the content of me into the stream
199   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
200 
201 private:
202 
203   gp_Pnt2d loc;
204   gp_Dir2d vdir;
205 
206 };
207 
208 #endif // _gp_Ax2d_HeaderFile
209