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_Ax1_HeaderFile
16 #define _gp_Ax1_HeaderFile
17 
18 #include <gp_Pnt.hxx>
19 #include <gp_Dir.hxx>
20 
21 class gp_Ax2;
22 class gp_Trsf;
23 class gp_Vec;
24 
25 //! Describes an axis in 3D space.
26 //! An axis is defined by:
27 //! -   its origin (also referred to as its "Location point"), and
28 //! -   its unit vector (referred to as its "Direction" or "main   Direction").
29 //! An axis is used:
30 //! -   to describe 3D geometric entities (for example, the
31 //! axis of a revolution entity). It serves the same purpose
32 //! as the STEP function "axis placement one axis", or
33 //! -   to define geometric transformations (axis of
34 //! symmetry, axis of rotation, and so on).
35 //! For example, this entity can be used to locate a geometric entity
36 //! or to define a symmetry axis.
37 class gp_Ax1
38 {
39 public:
40 
41   DEFINE_STANDARD_ALLOC
42 
43   //! Creates an axis object representing Z axis of
44   //! the reference coordinate system.
gp_Ax1()45   gp_Ax1()
46   : loc(0.,0.,0.), vdir(0.,0.,1.)
47   {}
48 
49   //! P is the location point and V is the direction of <me>.
gp_Ax1(const gp_Pnt & theP,const gp_Dir & theV)50   gp_Ax1 (const gp_Pnt& theP, const gp_Dir& theV)
51   : loc(theP), vdir (theV)
52   {}
53 
54   //! Assigns V as the "Direction"  of this axis.
SetDirection(const gp_Dir & theV)55   void SetDirection (const gp_Dir& theV) { vdir = theV; }
56 
57   //! Assigns  P as the origin of this axis.
SetLocation(const gp_Pnt & theP)58   void SetLocation (const gp_Pnt& theP) { loc = theP; }
59 
60   //! Returns the direction of <me>.
Direction() const61   const gp_Dir& Direction() const { return vdir; }
62 
63   //! Returns the location point of <me>.
Location() const64   const gp_Pnt& Location() const { return loc; }
65 
66   //! Returns True if  :
67   //! . the angle between <me> and <Other> is lower or equal
68   //! to <AngularTolerance> and
69   //! . the distance between <me>.Location() and <Other> is lower
70   //! or equal to <LinearTolerance> and
71   //! . the distance between <Other>.Location() and <me> is lower
72   //! or equal to LinearTolerance.
73   Standard_EXPORT Standard_Boolean IsCoaxial (const gp_Ax1& Other, const Standard_Real AngularTolerance, const Standard_Real LinearTolerance) const;
74 
75   //! Returns True if the direction of this and another axis are normal to each other.
76   //! That is, if the angle between the two axes is equal to Pi/2.
77   //! Note: the tolerance criterion is given by theAngularTolerance.
IsNormal(const gp_Ax1 & theOther,const Standard_Real theAngularTolerance) const78   Standard_Boolean IsNormal (const gp_Ax1& theOther, const Standard_Real theAngularTolerance) const
79   {
80     return vdir.IsNormal (theOther.vdir, theAngularTolerance);
81   }
82 
83   //! Returns True if the direction of this and another axis are parallel with opposite orientation.
84   //! That is, if the angle between the two axes is equal to Pi.
85   //! Note: the tolerance criterion is given by theAngularTolerance.
IsOpposite(const gp_Ax1 & theOther,const Standard_Real theAngularTolerance) const86   Standard_Boolean IsOpposite (const gp_Ax1& theOther, const Standard_Real theAngularTolerance) const
87   {
88     return vdir.IsOpposite (theOther.vdir, theAngularTolerance);
89   }
90 
91   //! Returns True if the direction of this and another axis are parallel with same orientation or opposite orientation.
92   //! That is, if the angle between the two axes is equal to 0 or Pi.
93   //! Note: the tolerance criterion is given by theAngularTolerance.
IsParallel(const gp_Ax1 & theOther,const Standard_Real theAngularTolerance) const94   Standard_Boolean IsParallel (const gp_Ax1& theOther, const Standard_Real theAngularTolerance) const
95   {
96     return vdir.IsParallel(theOther.vdir, theAngularTolerance);
97   }
98 
99   //! Computes the angular value, in radians, between this.Direction() and theOther.Direction().
100   //! Returns the angle between 0 and 2*PI radians.
Angle(const gp_Ax1 & theOther) const101   Standard_Real Angle (const gp_Ax1& theOther) const { return vdir.Angle (theOther.vdir); }
102 
103   //! Reverses the unit vector of this axis and assigns the result to this axis.
Reverse()104   void Reverse() { vdir.Reverse(); }
105 
106   //! Reverses the unit vector of this axis and creates a new one.
Reversed() const107   Standard_NODISCARD gp_Ax1 Reversed() const
108   {
109     gp_Dir D = vdir.Reversed();
110     return gp_Ax1 (loc, D);
111   }
112 
113   //! Performs the symmetrical transformation of an axis
114   //! placement with respect to the point P which is the
115   //! center of the symmetry and assigns the result to this axis.
116   Standard_EXPORT void Mirror (const gp_Pnt& P);
117 
118   //! Performs the symmetrical transformation of an axis
119   //! placement with respect to the point P which is the
120   //! center of the symmetry and creates a new axis.
121   Standard_NODISCARD Standard_EXPORT gp_Ax1 Mirrored (const gp_Pnt& P) const;
122 
123   //! Performs the symmetrical transformation of an axis
124   //! placement with respect to an axis placement which
125   //! is the axis of the symmetry and assigns the result to this axis.
126   Standard_EXPORT void Mirror (const gp_Ax1& A1);
127 
128   //! Performs the symmetrical transformation of an axis
129   //! placement with respect to an axis placement which
130   //! is the axis of the symmetry and creates a new axis.
131   Standard_NODISCARD Standard_EXPORT gp_Ax1 Mirrored (const gp_Ax1& A1) const;
132 
133   //! Performs the symmetrical transformation of an axis
134   //! placement with respect to a plane. The axis placement
135   //! <A2> locates the plane of the symmetry :
136   //! (Location, XDirection, YDirection) and assigns the result to this axis.
137   Standard_EXPORT void Mirror (const gp_Ax2& A2);
138 
139   //! Performs the symmetrical transformation of an axis
140   //! placement with respect to a plane. The axis placement
141   //! <A2> locates the plane of the symmetry :
142   //! (Location, XDirection, YDirection) and creates a new axis.
143   Standard_NODISCARD Standard_EXPORT gp_Ax1 Mirrored (const gp_Ax2& A2) const;
144 
145   //! Rotates this axis at an angle theAngRad (in radians) about the axis theA1
146   //! and assigns the result to this axis.
Rotate(const gp_Ax1 & theA1,const Standard_Real theAngRad)147   void Rotate (const gp_Ax1& theA1, const Standard_Real theAngRad)
148   {
149     loc .Rotate (theA1, theAngRad);
150     vdir.Rotate (theA1, theAngRad);
151   }
152 
153   //! Rotates this axis at an angle theAngRad (in radians) about the axis theA1
154   //! and creates a new one.
Rotated(const gp_Ax1 & theA1,const Standard_Real theAngRad) const155   Standard_NODISCARD gp_Ax1 Rotated (const gp_Ax1& theA1, const Standard_Real theAngRad) const
156   {
157     gp_Ax1 A = *this;
158     A.Rotate (theA1, theAngRad);
159     return A;
160   }
161 
162   //! Applies a scaling transformation to this axis with:
163   //! - scale factor theS, and
164   //! - center theP and assigns the result to this axis.
Scale(const gp_Pnt & theP,const Standard_Real theS)165   void Scale (const gp_Pnt& theP, const Standard_Real theS)
166   {
167     loc.Scale (theP, theS);
168     if (theS < 0.0) { vdir.Reverse(); }
169   }
170 
171   //! Applies a scaling transformation to this axis with:
172   //! - scale factor theS, and
173   //! - center theP and creates a new axis.
Scaled(const gp_Pnt & theP,const Standard_Real theS) const174   Standard_NODISCARD gp_Ax1 Scaled (const gp_Pnt& theP, const Standard_Real theS) const
175   {
176     gp_Ax1 A1 = *this;
177     A1.Scale (theP, theS);
178     return A1;
179   }
180 
181   //! Applies the transformation theT to this axis and assigns the result to this axis.
Transform(const gp_Trsf & theT)182   void Transform (const gp_Trsf& theT)
183   {
184     loc .Transform (theT);
185     vdir.Transform (theT);
186   }
187 
188   //! Applies the transformation theT to this axis and creates a new one.
189   //!
190   //! Translates an axis plaxement in the direction of the vector <V>.
191   //! The magnitude of the translation is the vector's magnitude.
Transformed(const gp_Trsf & theT) const192   Standard_NODISCARD gp_Ax1 Transformed (const gp_Trsf& theT) const
193   {
194     gp_Ax1 A1 = *this;
195     A1.Transform (theT);
196     return A1;
197   }
198 
199   //! Translates this axis by the vector theV, and assigns the result to this axis.
Translate(const gp_Vec & theV)200   void Translate (const gp_Vec& theV) { loc.Translate (theV); }
201 
202   //! Translates this axis by the vector theV,
203   //! and creates a new one.
Translated(const gp_Vec & theV) const204   Standard_NODISCARD gp_Ax1 Translated (const gp_Vec& theV) const
205   {
206     gp_Ax1 A1 = *this;
207     (A1.loc).Translate (theV);
208     return A1;
209   }
210 
211   //! Translates this axis by:
212   //! the vector (theP1, theP2) defined from point theP1 to point theP2.
213   //! and assigns the result to this axis.
Translate(const gp_Pnt & theP1,const gp_Pnt & theP2)214   void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { loc.Translate (theP1, theP2); }
215 
216   //! Translates this axis by:
217   //! the vector (theP1, theP2) defined from point theP1 to point theP2.
218   //! and creates a new one.
Translated(const gp_Pnt & theP1,const gp_Pnt & theP2) const219   Standard_NODISCARD gp_Ax1 Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const
220   {
221     gp_Ax1 A1 = *this;
222     (A1.loc).Translate (theP1, theP2);
223     return A1;
224   }
225 
226   //! Dumps the content of me into the stream
227   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
228 
229   //! Inits the content of me from the stream
230   Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos);
231 
232 private:
233 
234   gp_Pnt loc;
235   gp_Dir vdir;
236 
237 };
238 
239 #endif // _gp_Ax1_HeaderFile
240