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_Ax2_HeaderFile
0016 #define _gp_Ax2_HeaderFile
0017 
0018 #include <gp_Ax1.hxx>
0019 #include <gp_Dir.hxx>
0020 #include <Precision.hxx>
0021 
0022 class gp_Trsf;
0023 class gp_Vec;
0024 
0025 //! Describes a right-handed coordinate system in 3D space.
0026 //! A coordinate system is defined by:
0027 //! -   its origin (also referred to as its "Location point"), and
0028 //! -   three orthogonal unit vectors, termed respectively the
0029 //! "X Direction", the "Y Direction" and the "Direction" (also
0030 //! referred to as the "main Direction").
0031 //! The "Direction" of the coordinate system is called its
0032 //! "main Direction" because whenever this unit vector is
0033 //! modified, the "X Direction" and the "Y Direction" are
0034 //! recomputed. However, when we modify either the "X
0035 //! Direction" or the "Y Direction", "Direction" is not modified.
0036 //! The "main Direction" is also the "Z Direction".
0037 //! Since an Ax2 coordinate system is right-handed, its
0038 //! "main Direction" is always equal to the cross product of
0039 //! its "X Direction" and "Y Direction". (To define a
0040 //! left-handed coordinate system, use gp_Ax3.)
0041 //! A coordinate system is used:
0042 //! -   to describe geometric entities, in particular to position
0043 //! them. The local coordinate system of a geometric
0044 //! entity serves the same purpose as the STEP function
0045 //! "axis placement two axes", or
0046 //! -   to define geometric transformations.
0047 //! Note: we refer to the "X Axis", "Y Axis" and "Z Axis",
0048 //! respectively, as to axes having:
0049 //! - the origin of the coordinate system as their origin, and
0050 //! -   the unit vectors "X Direction", "Y Direction" and "main
0051 //! Direction", respectively, as their unit vectors.
0052 //! The "Z Axis" is also the "main Axis".
0053 class gp_Ax2 
0054 {
0055 public:
0056 
0057   DEFINE_STANDARD_ALLOC
0058 
0059   //! Creates an object corresponding to the reference
0060   //! coordinate system (OXYZ).
0061   gp_Ax2() : vydir(0.,1.,0.)
0062   // vxdir(1.,0.,0.) use default ctor of gp_Dir, as it creates the same dir(1,0,0)
0063   {}
0064 
0065   //! Creates an axis placement with an origin P such that:
0066   //! -   N is the Direction, and
0067   //! -   the "X Direction" is normal to N, in the plane
0068   //! defined by the vectors (N, Vx): "X
0069   //! Direction" = (N ^ Vx) ^ N,
0070   //! Exception: raises ConstructionError if N and Vx are parallel (same or opposite orientation).
0071   gp_Ax2 (const gp_Pnt& P, const gp_Dir& N, const gp_Dir& Vx)
0072   : axis (P, N),
0073     vydir (N),
0074     vxdir (N)
0075   {
0076     vxdir.CrossCross(Vx, N);
0077     vydir.Cross(vxdir);
0078   }
0079 
0080   //! Creates -   a coordinate system with an origin P, where V
0081   //! gives the "main Direction" (here, "X Direction" and "Y
0082   //! Direction" are defined automatically).
0083   Standard_EXPORT gp_Ax2(const gp_Pnt& P, const gp_Dir& V);
0084 
0085   //! Assigns the origin and "main Direction" of the axis A1 to
0086   //! this coordinate system, then recomputes its "X Direction" and "Y Direction".
0087   //! Note: The new "X Direction" is computed as follows:
0088   //! new "X Direction" = V1 ^(previous "X Direction" ^ V)
0089   //! where V is the "Direction" of A1.
0090   //! Exceptions
0091   //! Standard_ConstructionError if A1 is parallel to the "X
0092   //! Direction" of this coordinate system.
0093   void SetAxis (const gp_Ax1& A1);
0094 
0095   //! Changes the "main Direction" of this coordinate system,
0096   //! then recomputes its "X Direction" and "Y Direction".
0097   //! Note: the new "X Direction" is computed as follows:
0098   //! new "X Direction" = V ^ (previous "X Direction" ^ V)
0099   //! Exceptions
0100   //! Standard_ConstructionError if V is parallel to the "X
0101   //! Direction" of this coordinate system.
0102   void SetDirection (const gp_Dir& V);
0103 
0104   //! Changes the "Location" point (origin) of <me>.
0105   void SetLocation (const gp_Pnt& theP) { axis.SetLocation (theP); }
0106 
0107   //! Changes the "Xdirection" of <me>. The main direction
0108   //! "Direction" is not modified, the "Ydirection" is modified.
0109   //! If <Vx> is not normal to the main direction then <XDirection>
0110   //! is computed as follows XDirection = Direction ^ (Vx ^ Direction).
0111   //! Exceptions
0112   //! Standard_ConstructionError if Vx or Vy is parallel to
0113   //! the "main Direction" of this coordinate system.
0114   void SetXDirection (const gp_Dir& theVx)
0115   {
0116     vxdir = axis.Direction().CrossCrossed (theVx, axis.Direction());
0117     vydir = axis.Direction().Crossed      (vxdir);
0118   }
0119 
0120   //! Changes the "Ydirection" of <me>. The main direction is not
0121   //! modified but the "Xdirection" is changed.
0122   //! If <Vy> is not normal to the main direction then "YDirection"
0123   //! is computed as  follows
0124   //! YDirection = Direction ^ (<Vy> ^ Direction).
0125   //! Exceptions
0126   //! Standard_ConstructionError if Vx or Vy is parallel to
0127   //! the "main Direction" of this coordinate system.
0128   void SetYDirection (const gp_Dir& theVy)
0129   {
0130     vxdir = theVy.Crossed (axis.Direction());
0131     vydir = (axis.Direction()).Crossed (vxdir);
0132   }
0133 
0134   //! Computes the angular value, in radians, between the main direction of
0135   //! <me> and the main direction of <theOther>. Returns the angle
0136   //! between 0 and PI in radians.
0137   Standard_Real Angle (const gp_Ax2& theOther) const { return axis.Angle (theOther.axis); }
0138 
0139   //! Returns the main axis of <me>. It is the "Location" point
0140   //! and the main "Direction".
0141   const gp_Ax1& Axis() const { return axis; }
0142 
0143   //! Returns the main direction of <me>.
0144   const gp_Dir& Direction() const { return axis.Direction(); }
0145 
0146   //! Returns the "Location" point (origin) of <me>.
0147   const gp_Pnt& Location() const { return axis.Location(); }
0148 
0149   //! Returns the "XDirection" of <me>.
0150   const gp_Dir& XDirection() const { return vxdir; }
0151 
0152   //! Returns the "YDirection" of <me>.
0153   const gp_Dir& YDirection() const { return vydir; }
0154 
0155   Standard_Boolean IsCoplanar (const gp_Ax2& Other, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const;
0156 
0157   //! Returns True if
0158   //! . the distance between <me> and the "Location" point of A1
0159   //! is lower of equal to LinearTolerance and
0160   //! . the main direction of <me> and the direction of A1 are normal.
0161   //! Note: the tolerance criterion for angular equality is given by AngularTolerance.
0162   Standard_Boolean IsCoplanar (const gp_Ax1& A1, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const;
0163 
0164   //! Performs a symmetrical transformation of this coordinate
0165   //! system with respect to:
0166   //! -   the point P, and assigns the result to this coordinate system.
0167   //! Warning
0168   //! This transformation is always performed on the origin.
0169   //! In case of a reflection with respect to a point:
0170   //! - the main direction of the coordinate system is not changed, and
0171   //! - the "X Direction" and the "Y Direction" are simply reversed
0172   //! In case of a reflection with respect to an axis or a plane:
0173   //! -   the transformation is applied to the "X Direction"
0174   //! and the "Y Direction", then
0175   //! -   the "main Direction" is recomputed as the cross
0176   //! product "X Direction" ^ "Y   Direction".
0177   //! This maintains the right-handed property of the
0178   //! coordinate system.
0179   Standard_EXPORT void Mirror (const gp_Pnt& P);
0180 
0181   //! Performs a symmetrical transformation of this coordinate
0182   //! system with respect to:
0183   //! -   the point P, and creates a new one.
0184   //! Warning
0185   //! This transformation is always performed on the origin.
0186   //! In case of a reflection with respect to a point:
0187   //! - the main direction of the coordinate system is not changed, and
0188   //! - the "X Direction" and the "Y Direction" are simply reversed
0189   //! In case of a reflection with respect to an axis or a plane:
0190   //! -   the transformation is applied to the "X Direction"
0191   //! and the "Y Direction", then
0192   //! -   the "main Direction" is recomputed as the cross
0193   //! product "X Direction" ^ "Y   Direction".
0194   //! This maintains the right-handed property of the
0195   //! coordinate system.
0196   Standard_NODISCARD Standard_EXPORT gp_Ax2 Mirrored (const gp_Pnt& P) const;
0197 
0198   //! Performs a symmetrical transformation of this coordinate
0199   //! system with respect to:
0200   //! -   the axis A1, and assigns the result to this coordinate systeme.
0201   //! Warning
0202   //! This transformation is always performed on the origin.
0203   //! In case of a reflection with respect to a point:
0204   //! - the main direction of the coordinate system is not changed, and
0205   //! - the "X Direction" and the "Y Direction" are simply reversed
0206   //! In case of a reflection with respect to an axis or a plane:
0207   //! -   the transformation is applied to the "X Direction"
0208   //! and the "Y Direction", then
0209   //! -   the "main Direction" is recomputed as the cross
0210   //! product "X Direction" ^ "Y   Direction".
0211   //! This maintains the right-handed property of the
0212   //! coordinate system.
0213   Standard_EXPORT void Mirror (const gp_Ax1& A1);
0214 
0215   //! Performs a symmetrical transformation of this coordinate
0216   //! system with respect to:
0217   //! -   the axis A1, and  creates a new one.
0218   //! Warning
0219   //! This transformation is always performed on the origin.
0220   //! In case of a reflection with respect to a point:
0221   //! - the main direction of the coordinate system is not changed, and
0222   //! - the "X Direction" and the "Y Direction" are simply reversed
0223   //! In case of a reflection with respect to an axis or a plane:
0224   //! -   the transformation is applied to the "X Direction"
0225   //! and the "Y Direction", then
0226   //! -   the "main Direction" is recomputed as the cross
0227   //! product "X Direction" ^ "Y   Direction".
0228   //! This maintains the right-handed property of the
0229   //! coordinate system.
0230   Standard_NODISCARD Standard_EXPORT gp_Ax2 Mirrored (const gp_Ax1& A1) const;
0231 
0232   //! Performs a symmetrical transformation of this coordinate
0233   //! system with respect to:
0234   //! -   the plane defined by the origin, "X Direction" and "Y
0235   //! Direction" of coordinate system A2 and  assigns the result to this coordinate systeme.
0236   //! Warning
0237   //! This transformation is always performed on the origin.
0238   //! In case of a reflection with respect to a point:
0239   //! - the main direction of the coordinate system is not changed, and
0240   //! - the "X Direction" and the "Y Direction" are simply reversed
0241   //! In case of a reflection with respect to an axis or a plane:
0242   //! -   the transformation is applied to the "X Direction"
0243   //! and the "Y Direction", then
0244   //! -   the "main Direction" is recomputed as the cross
0245   //! product "X Direction" ^ "Y   Direction".
0246   //! This maintains the right-handed property of the
0247   //! coordinate system.
0248   Standard_EXPORT void Mirror (const gp_Ax2& A2);
0249 
0250   //! Performs a symmetrical transformation of this coordinate
0251   //! system with respect to:
0252   //! -   the plane defined by the origin, "X Direction" and "Y
0253   //! Direction" of coordinate system A2 and creates a new one.
0254   //! Warning
0255   //! This transformation is always performed on the origin.
0256   //! In case of a reflection with respect to a point:
0257   //! - the main direction of the coordinate system is not changed, and
0258   //! - the "X Direction" and the "Y Direction" are simply reversed
0259   //! In case of a reflection with respect to an axis or a plane:
0260   //! -   the transformation is applied to the "X Direction"
0261   //! and the "Y Direction", then
0262   //! -   the "main Direction" is recomputed as the cross
0263   //! product "X Direction" ^ "Y   Direction".
0264   //! This maintains the right-handed property of the
0265   //! coordinate system.
0266   Standard_NODISCARD Standard_EXPORT gp_Ax2 Mirrored (const gp_Ax2& A2) const;
0267 
0268   void Rotate (const gp_Ax1& theA1, const Standard_Real theAng)
0269   {
0270     gp_Pnt aTemp = axis.Location();
0271     aTemp.Rotate (theA1, theAng);
0272     axis.SetLocation (aTemp);
0273     vxdir.Rotate (theA1, theAng);
0274     vydir.Rotate (theA1, theAng);
0275     axis.SetDirection (vxdir.Crossed (vydir));
0276   }
0277 
0278   //! Rotates an axis placement. <theA1> is the axis of the rotation.
0279   //! theAng is the angular value of the rotation in radians.
0280   Standard_NODISCARD gp_Ax2 Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const
0281   {
0282     gp_Ax2 aTemp = *this;
0283     aTemp.Rotate (theA1, theAng);
0284     return aTemp;
0285   } 
0286 
0287   void Scale (const gp_Pnt& theP, const Standard_Real theS)
0288   {
0289     gp_Pnt aTemp = axis.Location();
0290     aTemp.Scale (theP, theS);
0291     axis.SetLocation (aTemp);
0292     if (theS < 0.0)
0293     {
0294       vxdir.Reverse();
0295       vydir.Reverse();
0296     }
0297   }
0298 
0299   //! Applies a scaling transformation on the axis placement.
0300   //! The "Location" point of the axisplacement is modified.
0301   //! Warnings :
0302   //! If the scale <S> is negative :
0303   //! . the main direction of the axis placement is not changed.
0304   //! . The "XDirection" and the "YDirection" are reversed.
0305   //! So the axis placement stay right handed.
0306   Standard_NODISCARD gp_Ax2 Scaled (const gp_Pnt& theP, const Standard_Real theS) const
0307   {
0308     gp_Ax2 aTemp = *this;
0309     aTemp.Scale (theP, theS);
0310     return aTemp;
0311   }
0312 
0313   void Transform (const gp_Trsf& theT)
0314   {
0315     gp_Pnt aTemp = axis.Location();
0316     aTemp.Transform (theT);
0317     axis.SetLocation (aTemp);
0318     vxdir.Transform (theT);
0319     vydir.Transform (theT);
0320     axis.SetDirection (vxdir.Crossed (vydir));
0321   }
0322 
0323   //! Transforms an axis placement with a Trsf.
0324   //! The "Location" point, the "XDirection" and the "YDirection" are transformed with theT.
0325   //! The resulting main "Direction" of <me> is the cross product between
0326   //! the "XDirection" and the "YDirection" after transformation.
0327   Standard_NODISCARD gp_Ax2 Transformed (const gp_Trsf& theT) const
0328   {
0329     gp_Ax2 aTemp = *this;
0330     aTemp.Transform (theT);
0331     return aTemp;
0332   }
0333   
0334   void Translate (const gp_Vec& theV) { axis.Translate (theV); }
0335 
0336   //! Translates an axis plaxement in the direction of the vector <theV>.
0337   //! The magnitude of the translation is the vector's magnitude.
0338   Standard_NODISCARD gp_Ax2 Translated (const gp_Vec& theV) const
0339   {
0340     gp_Ax2 aTemp = *this;
0341     aTemp.Translate (theV);
0342     return aTemp;
0343   }
0344 
0345   void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { axis.Translate (theP1, theP2); }
0346 
0347   //! Translates an axis placement from the point <theP1> to the point <theP2>.
0348   Standard_NODISCARD gp_Ax2 Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const
0349   {
0350     gp_Ax2 aTemp = *this;
0351     aTemp.Translate (theP1, theP2);
0352     return aTemp;
0353   }
0354 
0355   //! Dumps the content of me into the stream
0356   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0357 
0358   //! Inits the content of me from the stream
0359   Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos);
0360 
0361 private:
0362 
0363   gp_Ax1 axis;
0364   gp_Dir vydir;
0365   gp_Dir vxdir;
0366 
0367 };
0368 
0369 // =======================================================================
0370 // function : SetAxis
0371 // purpose  :
0372 // =======================================================================
0373 inline void gp_Ax2::SetAxis (const gp_Ax1& theA1)
0374 {
0375   Standard_Real a =  theA1.Direction() * vxdir;
0376   if (Abs(Abs(a) - 1.) <= Precision::Angular())
0377   {
0378     if (a > 0.)
0379     {
0380       vxdir = vydir;
0381       vydir = axis.Direction();
0382       axis = theA1;
0383     }
0384     else
0385     {
0386       vxdir = axis.Direction();
0387       axis = theA1;
0388     }
0389   }
0390   else
0391   {
0392     axis = theA1;
0393     vxdir = axis.Direction().CrossCrossed (vxdir, axis.Direction());
0394     vydir = axis.Direction().Crossed      (vxdir);
0395   }
0396 }
0397 
0398 // =======================================================================
0399 // function : SetDirection
0400 // purpose  :
0401 // =======================================================================
0402 inline void gp_Ax2::SetDirection (const gp_Dir& theV)
0403 { 
0404   Standard_Real a =  theV * vxdir;
0405   if (Abs(Abs(a) - 1.) <= Precision::Angular())
0406   {
0407     if(a > 0.)
0408     {
0409       vxdir = vydir;
0410       vydir = axis.Direction();
0411       axis.SetDirection (theV);
0412     }
0413     else
0414     {
0415       vxdir = axis.Direction();
0416       axis.SetDirection (theV);
0417     }
0418   }
0419   else
0420   {
0421     axis.SetDirection (theV);
0422     vxdir = theV.CrossCrossed (vxdir, theV);
0423     vydir = theV.Crossed (vxdir);
0424   }
0425 }
0426 
0427 // =======================================================================
0428 // function : IsCoplanar
0429 // purpose  :
0430 // =======================================================================
0431 inline Standard_Boolean gp_Ax2::IsCoplanar (const gp_Ax2& theOther,
0432                                             const Standard_Real theLinearTolerance,
0433                                             const Standard_Real theAngularTolerance) const
0434 {
0435   const gp_Dir& DD =          axis.Direction();
0436   const gp_Pnt& PP =          axis.Location();
0437   const gp_Pnt& OP = theOther.axis.Location();
0438   Standard_Real D1 = (DD.X() * (OP.X() - PP.X())
0439                     + DD.Y() * (OP.Y() - PP.Y())
0440                     + DD.Z() * (OP.Z() - PP.Z()));
0441   if (D1 < 0)
0442   {
0443     D1 = -D1;
0444   }
0445   return D1 <= theLinearTolerance
0446       && axis.IsParallel (theOther.axis, theAngularTolerance);
0447 }
0448 
0449 // =======================================================================
0450 // function : IsCoplanar
0451 // purpose  :
0452 // =======================================================================
0453 inline Standard_Boolean gp_Ax2::IsCoplanar (const gp_Ax1& theA,
0454                                             const Standard_Real theLinearTolerance,
0455                                             const Standard_Real theAngularTolerance) const
0456 {
0457   const gp_Dir& DD = axis.Direction();
0458   const gp_Pnt& PP = axis.Location();
0459   const gp_Pnt& AP = theA.Location();
0460   Standard_Real D1 = (DD.X() * (AP.X() - PP.X()) + 
0461                       DD.Y() * (AP.Y() - PP.Y()) + 
0462                       DD.Z() * (AP.Z() - PP.Z()));
0463   if (D1 < 0)
0464   {
0465     D1 = -D1;
0466   }
0467   return D1 <= theLinearTolerance
0468       && axis.IsNormal (theA, theAngularTolerance);
0469 }
0470 
0471 #endif // _gp_Ax2_HeaderFile