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_Ax2d_HeaderFile
16 #define _gp_Ax2d_HeaderFile
18 #include <gp_Pnt2d.hxx>
19 #include <gp_Dir2d.hxx>
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:
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).
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.
48 //! Creates an axis object representing X axis of the reference co-ordinate system.
49 gp_Ax2d() : loc(0.,0.)
50 //vdir(1.,0.) use default ctor of gp_Dir2d, as it creates the same dir (1,0)
54 //! <theP> is the "Location" point of the axis placement
55 //! and theV is the "Direction" of the axis placement.
56 gp_Ax2d (const gp_Pnt2d& theP, const gp_Dir2d& theV)
61 //! Changes the "Location" point (origin) of <me>.
62 void SetLocation (const gp_Pnt2d& theP) { loc = theP; }
64 //! Changes the direction of <me>.
65 void SetDirection (const gp_Dir2d& theV) { vdir = theV; }
67 //! Returns the origin of <me>.
68 const gp_Pnt2d& Location() const { return loc; }
70 //! Returns the direction of <me>.
71 const gp_Dir2d& Direction() const { return vdir; }
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;
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.
85 Standard_Boolean IsNormal (const gp_Ax2d& theOther, const Standard_Real theAngularTolerance) const
87 return vdir.IsNormal (theOther.vdir, theAngularTolerance);
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.
93 Standard_Boolean IsOpposite (const gp_Ax2d& theOther, const Standard_Real theAngularTolerance) const
95 return vdir.IsOpposite (theOther.vdir, theAngularTolerance);
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.
102 Standard_Boolean IsParallel (const gp_Ax2d& theOther, const Standard_Real theAngularTolerance) const
104 return vdir.IsParallel (theOther.vdir, theAngularTolerance);
107 //! Computes the angle, in radians, between this axis and the axis theOther.
108 //! The value of the angle is between -Pi and Pi.
109 Standard_Real Angle (const gp_Ax2d& theOther) const { return vdir.Angle (theOther.vdir); }
111 //! Reverses the direction of <me> and assigns the result to this axis.
112 void Reverse() { vdir.Reverse(); }
114 //! Computes a new axis placement with a direction opposite to the direction of <me>.
115 Standard_NODISCARD gp_Ax2d Reversed() const
117 gp_Ax2d aTemp = *this;
122 Standard_EXPORT void Mirror (const gp_Pnt2d& P);
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;
129 Standard_EXPORT void Mirror (const gp_Ax2d& A);
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;
136 void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng)
138 loc.Rotate (theP, theAng);
139 vdir.Rotate (theAng);
142 //! Rotates an axis placement. <theP> is the center of the rotation.
143 //! theAng is the angular value of the rotation in radians.
144 Standard_NODISCARD gp_Ax2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const
147 anA.Rotate (theP, theAng);
151 Standard_EXPORT void Scale (const gp_Pnt2d& P, const Standard_Real S);
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.
156 Standard_NODISCARD gp_Ax2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const
159 anA.Scale (theP, theS);
163 void Transform (const gp_Trsf2d& theT)
165 loc .Transform (theT);
166 vdir.Transform (theT);
169 //! Transforms an axis placement with a Trsf.
170 Standard_NODISCARD gp_Ax2d Transformed (const gp_Trsf2d& theT) const
173 anA.Transform (theT);
177 void Translate (const gp_Vec2d& theV) { loc.Translate (theV); }
179 //! Translates an axis placement in the direction of the vector theV.
180 //! The magnitude of the translation is the vector's magnitude.
181 Standard_NODISCARD gp_Ax2d Translated (const gp_Vec2d& theV) const
184 (anA.loc).Translate (theV);
188 void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { loc.Translate (theP1, theP2); }
190 //! Translates an axis placement from the point theP1 to the point theP2.
191 Standard_NODISCARD gp_Ax2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const
194 (anA.loc).Translate (gp_Vec2d (theP1, theP2));
198 //! Dumps the content of me into the stream
199 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
208 #endif // _gp_Ax2d_HeaderFile