Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:43

0001 // Copyright (c) 1991-1999 Matra Datavision
0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _gp_Ax2d_HeaderFile
0016 #define _gp_Ax2d_HeaderFile
0017 
0018 #include <gp_Pnt2d.hxx>
0019 #include <gp_Dir2d.hxx>
0020 
0021 class gp_Trsf2d;
0022 class gp_Vec2d;
0023 
0024 //! Describes an axis in the plane (2D space).
0025 //! An axis is defined by:
0026 //! -   its origin (also referred to as its "Location point"),   and
0027 //! -   its unit vector (referred to as its "Direction").
0028 //! An axis implicitly defines a direct, right-handed
0029 //! coordinate system in 2D space by:
0030 //! -   its origin,
0031 //! - its "Direction" (giving the "X Direction" of the coordinate system), and
0032 //! -   the unit vector normal to "Direction" (positive angle
0033 //! measured in the trigonometric sense).
0034 //! An axis is used:
0035 //! -   to describe 2D geometric entities (for example, the
0036 //! axis which defines angular coordinates on a circle).
0037 //! It serves for the same purpose as the STEP function
0038 //! "axis placement one axis", or
0039 //! -   to define geometric transformations (axis of
0040 //! symmetry, axis of rotation, and so on).
0041 //! Note: to define a left-handed 2D coordinate system, use gp_Ax22d.
0042 class gp_Ax2d 
0043 {
0044 public:
0045 
0046   DEFINE_STANDARD_ALLOC
0047 
0048   //! Creates an axis object representing X axis of the reference co-ordinate system.
0049   gp_Ax2d() : loc(0.,0.)
0050   //vdir(1.,0.) use default ctor of gp_Dir2d, as it creates the same dir (1,0)
0051   {}
0052 
0053   //! Creates an Ax2d.
0054   //! <theP> is the "Location" point of the axis placement
0055   //! and theV is the "Direction" of the axis placement.
0056   gp_Ax2d (const gp_Pnt2d& theP, const gp_Dir2d& theV)
0057   : loc (theP),
0058     vdir (theV)
0059   {}
0060 
0061   //! Changes the "Location" point (origin) of <me>.
0062   void SetLocation (const gp_Pnt2d& theP) { loc = theP; }
0063 
0064   //! Changes the direction of <me>.
0065   void SetDirection (const gp_Dir2d& theV) { vdir = theV; }
0066 
0067   //! Returns the origin of <me>.
0068   const gp_Pnt2d& Location() const { return loc; }
0069 
0070   //! Returns the direction of <me>.
0071   const gp_Dir2d& Direction() const { return vdir; }
0072 
0073   //! Returns True if  :
0074   //! . the angle between <me> and <Other> is lower or equal
0075   //! to <AngularTolerance> and
0076   //! . the distance between <me>.Location() and <Other> is lower
0077   //! or equal to <LinearTolerance> and
0078   //! . the distance between <Other>.Location() and <me> is lower
0079   //! or equal to LinearTolerance.
0080   Standard_EXPORT Standard_Boolean IsCoaxial (const gp_Ax2d& Other, const Standard_Real AngularTolerance, const Standard_Real LinearTolerance) const;
0081   
0082   //! Returns true if this axis and the axis theOther are normal to each other.
0083   //! That is, if the angle between the two axes is equal to Pi/2 or -Pi/2.
0084   //! Note: the tolerance criterion is given by theAngularTolerance.
0085   Standard_Boolean IsNormal (const gp_Ax2d& theOther, const Standard_Real theAngularTolerance) const
0086   {
0087     return vdir.IsNormal (theOther.vdir, theAngularTolerance);
0088   }
0089 
0090   //! Returns true if this axis and the axis theOther are parallel, and have opposite orientations. 
0091   //! That is, if the angle between the two axes is equal to Pi or -Pi.
0092   //! Note: the tolerance criterion is given by theAngularTolerance.
0093   Standard_Boolean IsOpposite (const gp_Ax2d& theOther, const Standard_Real theAngularTolerance) const
0094   {
0095     return vdir.IsOpposite (theOther.vdir, theAngularTolerance);
0096   }
0097 
0098   //! Returns true if this axis and the axis theOther are parallel,
0099   //! and have either the same or opposite orientations.
0100   //! That is, if the angle between the two axes is equal to 0, Pi or -Pi.
0101   //! Note: the tolerance criterion is given by theAngularTolerance.
0102   Standard_Boolean IsParallel (const gp_Ax2d& theOther, const Standard_Real theAngularTolerance) const
0103   {
0104     return vdir.IsParallel (theOther.vdir, theAngularTolerance);
0105   }
0106 
0107   //! Computes the angle, in radians, between this axis and the axis theOther.
0108   //! The value of the angle is between -Pi and Pi.
0109   Standard_Real Angle (const gp_Ax2d& theOther) const { return vdir.Angle (theOther.vdir); }
0110 
0111   //! Reverses the direction of <me> and assigns the result to this axis.
0112   void Reverse() { vdir.Reverse(); }
0113 
0114   //! Computes a new axis placement with a direction opposite to the direction of <me>.
0115   Standard_NODISCARD gp_Ax2d Reversed() const
0116   { 
0117     gp_Ax2d aTemp = *this;
0118     aTemp.Reverse();
0119     return aTemp;
0120   }
0121 
0122   Standard_EXPORT void Mirror (const gp_Pnt2d& P);
0123 
0124   //! Performs the symmetrical transformation of an axis
0125   //! placement with respect to the point P which is the
0126   //! center of the symmetry.
0127   Standard_NODISCARD Standard_EXPORT gp_Ax2d Mirrored (const gp_Pnt2d& P) const;
0128 
0129   Standard_EXPORT void Mirror (const gp_Ax2d& A);
0130 
0131   //! Performs the symmetrical transformation of an axis
0132   //! placement with respect to an axis placement which
0133   //! is the axis of the symmetry.
0134   Standard_NODISCARD Standard_EXPORT gp_Ax2d Mirrored (const gp_Ax2d& A) const;
0135 
0136   void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng)
0137   {
0138     loc.Rotate (theP, theAng);
0139     vdir.Rotate (theAng);
0140   }
0141 
0142   //! Rotates an axis placement. <theP> is the center of the rotation.
0143   //! theAng is the angular value of the rotation in radians.
0144   Standard_NODISCARD gp_Ax2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const
0145   {
0146     gp_Ax2d anA = *this;
0147     anA.Rotate (theP, theAng);
0148     return anA;
0149   }
0150 
0151   Standard_EXPORT void Scale (const gp_Pnt2d& P, const Standard_Real S);
0152 
0153   //! Applies a scaling transformation on the axis placement.
0154   //! The "Location" point of the axisplacement is modified.
0155   //! The "Direction" is reversed if the scale is negative.
0156   Standard_NODISCARD gp_Ax2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const
0157   {
0158     gp_Ax2d anA = *this;
0159     anA.Scale (theP, theS);
0160     return anA;
0161   }
0162 
0163   void Transform (const gp_Trsf2d& theT)
0164   {
0165     loc .Transform (theT);
0166     vdir.Transform (theT);
0167   }
0168 
0169   //! Transforms an axis placement with a Trsf.
0170   Standard_NODISCARD gp_Ax2d Transformed (const gp_Trsf2d& theT) const
0171   {
0172     gp_Ax2d anA = *this;
0173     anA.Transform (theT);
0174     return anA;
0175   }
0176 
0177   void Translate (const gp_Vec2d& theV) { loc.Translate (theV); }
0178 
0179   //! Translates an axis placement in the direction of the vector theV.
0180   //! The magnitude of the translation is the vector's magnitude.
0181   Standard_NODISCARD gp_Ax2d Translated (const gp_Vec2d& theV) const
0182   {
0183     gp_Ax2d anA = *this;
0184     (anA.loc).Translate (theV); 
0185     return anA;
0186   }
0187 
0188   void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { loc.Translate (theP1, theP2); }
0189 
0190   //! Translates an axis placement from the point theP1 to the point theP2.
0191   Standard_NODISCARD gp_Ax2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const
0192   {
0193     gp_Ax2d anA = *this;
0194     (anA.loc).Translate (gp_Vec2d (theP1, theP2));
0195     return anA;
0196   }
0197 
0198   //! Dumps the content of me into the stream
0199   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0200 
0201 private:
0202 
0203   gp_Pnt2d loc;
0204   gp_Dir2d vdir;
0205 
0206 };
0207 
0208 #endif // _gp_Ax2d_HeaderFile