#ifndef _gp_Ax2_HeaderFile
#define _gp_Ax2_HeaderFile
-#include <Standard.hxx>
-#include <Standard_DefineAlloc.hxx>
-#include <Standard_Handle.hxx>
-
#include <gp_Ax1.hxx>
#include <gp_Dir.hxx>
-#include <Standard_Real.hxx>
-#include <Standard_Boolean.hxx>
+#include <Precision.hxx>
+
class Standard_ConstructionError;
class gp_Pnt;
-class gp_Dir;
-class gp_Ax1;
class gp_Trsf;
class gp_Vec;
-
-
//! Describes a right-handed coordinate system in 3D space.
//! A coordinate system is defined by:
//! - its origin (also referred to as its "Location point"), and
DEFINE_STANDARD_ALLOC
-
//! Creates an object corresponding to the reference
//! coordinate system (OXYZ).
- gp_Ax2();
-
+ gp_Ax2() : vydir(0.,1.,0.)
+ // vxdir(1.,0.,0.) use default ctor of gp_Dir, as it creates the same dir(1,0,0)
+ {}
//! Creates an axis placement with an origin P such that:
//! - N is the Direction, and
//! defined by the vectors (N, Vx): "X
//! Direction" = (N ^ Vx) ^ N,
//! Exception: raises ConstructionError if N and Vx are parallel (same or opposite orientation).
- gp_Ax2(const gp_Pnt& P, const gp_Dir& N, const gp_Dir& Vx);
-
+ gp_Ax2 (const gp_Pnt& P, const gp_Dir& N, const gp_Dir& Vx)
+ : axis (P, N),
+ vydir (N),
+ vxdir (N)
+ {
+ vxdir.CrossCross(Vx, N);
+ vydir.Cross(vxdir);
+ }
//! Creates - a coordinate system with an origin P, where V
//! gives the "main Direction" (here, "X Direction" and "Y
//! Direction" are defined automatically).
Standard_EXPORT gp_Ax2(const gp_Pnt& P, const gp_Dir& V);
-
+
//! Assigns the origin and "main Direction" of the axis A1 to
//! this coordinate system, then recomputes its "X Direction" and "Y Direction".
//! Note: The new "X Direction" is computed as follows:
//! Standard_ConstructionError if A1 is parallel to the "X
//! Direction" of this coordinate system.
void SetAxis (const gp_Ax1& A1);
-
//! Changes the "main Direction" of this coordinate system,
//! then recomputes its "X Direction" and "Y Direction".
//! Standard_ConstructionError if V is parallel to the "X
//! Direction" of this coordinate system.
void SetDirection (const gp_Dir& V);
-
//! Changes the "Location" point (origin) of <me>.
- void SetLocation (const gp_Pnt& P);
-
+ void SetLocation (const gp_Pnt& theP) { axis.SetLocation (theP); }
//! Changes the "Xdirection" of <me>. The main direction
//! "Direction" is not modified, the "Ydirection" is modified.
//! Exceptions
//! Standard_ConstructionError if Vx or Vy is parallel to
//! the "main Direction" of this coordinate system.
- void SetXDirection (const gp_Dir& Vx);
-
+ void SetXDirection (const gp_Dir& theVx)
+ {
+ vxdir = axis.Direction().CrossCrossed (theVx, axis.Direction());
+ vydir = axis.Direction().Crossed (vxdir);
+ }
//! Changes the "Ydirection" of <me>. The main direction is not
//! modified but the "Xdirection" is changed.
//! Exceptions
//! Standard_ConstructionError if Vx or Vy is parallel to
//! the "main Direction" of this coordinate system.
- void SetYDirection (const gp_Dir& Vy);
-
+ void SetYDirection (const gp_Dir& theVy)
+ {
+ vxdir = theVy.Crossed (axis.Direction());
+ vydir = (axis.Direction()).Crossed (vxdir);
+ }
//! Computes the angular value, in radians, between the main direction of
- //! <me> and the main direction of <Other>. Returns the angle
+ //! <me> and the main direction of <theOther>. Returns the angle
//! between 0 and PI in radians.
- Standard_Real Angle (const gp_Ax2& Other) const;
-
+ Standard_Real Angle (const gp_Ax2& theOther) const { return axis.Angle (theOther.axis); }
//! Returns the main axis of <me>. It is the "Location" point
//! and the main "Direction".
- const gp_Ax1& Axis() const;
-
+ const gp_Ax1& Axis() const { return axis; }
//! Returns the main direction of <me>.
- const gp_Dir& Direction() const;
-
+ const gp_Dir& Direction() const { return axis.Direction(); }
//! Returns the "Location" point (origin) of <me>.
- const gp_Pnt& Location() const;
-
+ const gp_Pnt& Location() const { return axis.Location(); }
//! Returns the "XDirection" of <me>.
- const gp_Dir& XDirection() const;
-
+ const gp_Dir& XDirection() const { return vxdir; }
//! Returns the "YDirection" of <me>.
- const gp_Dir& YDirection() const;
-
+ const gp_Dir& YDirection() const { return vydir; }
+
Standard_Boolean IsCoplanar (const gp_Ax2& Other, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const;
-
//! Returns True if
//! . the distance between <me> and the "Location" point of A1
//! is lower of equal to LinearTolerance and
//! . the main direction of <me> and the direction of A1 are normal.
//! Note: the tolerance criterion for angular equality is given by AngularTolerance.
- Standard_Boolean IsCoplanar (const gp_Ax1& A1, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const;
-
+ Standard_Boolean IsCoplanar (const gp_Ax1& A1, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const;
//! Performs a symmetrical transformation of this coordinate
//! system with respect to:
//! This maintains the right-handed property of the
//! coordinate system.
Standard_EXPORT void Mirror (const gp_Pnt& P);
-
//! Performs a symmetrical transformation of this coordinate
//! system with respect to:
//! This maintains the right-handed property of the
//! coordinate system.
Standard_NODISCARD Standard_EXPORT gp_Ax2 Mirrored (const gp_Pnt& P) const;
-
//! Performs a symmetrical transformation of this coordinate
//! system with respect to:
//! This maintains the right-handed property of the
//! coordinate system.
Standard_EXPORT void Mirror (const gp_Ax1& A1);
-
//! Performs a symmetrical transformation of this coordinate
//! system with respect to:
//! This maintains the right-handed property of the
//! coordinate system.
Standard_NODISCARD Standard_EXPORT gp_Ax2 Mirrored (const gp_Ax1& A1) const;
-
//! Performs a symmetrical transformation of this coordinate
//! system with respect to:
//! This maintains the right-handed property of the
//! coordinate system.
Standard_EXPORT void Mirror (const gp_Ax2& A2);
-
//! Performs a symmetrical transformation of this coordinate
//! system with respect to:
//! This maintains the right-handed property of the
//! coordinate system.
Standard_NODISCARD Standard_EXPORT gp_Ax2 Mirrored (const gp_Ax2& A2) const;
-
- void Rotate (const gp_Ax1& A1, const Standard_Real Ang);
-
- //! Rotates an axis placement. <A1> is the axis of the
- //! rotation . Ang is the angular value of the rotation
- //! in radians.
- Standard_NODISCARD gp_Ax2 Rotated (const gp_Ax1& A1, const Standard_Real Ang) const;
-
- void Scale (const gp_Pnt& P, const Standard_Real S);
-
+ void Rotate (const gp_Ax1& theA1, const Standard_Real theAng)
+ {
+ gp_Pnt aTemp = axis.Location();
+ aTemp.Rotate (theA1, theAng);
+ axis.SetLocation (aTemp);
+ vxdir.Rotate (theA1, theAng);
+ vydir.Rotate (theA1, theAng);
+ axis.SetDirection (vxdir.Crossed (vydir));
+ }
+
+ //! Rotates an axis placement. <theA1> is the axis of the rotation.
+ //! theAng is the angular value of the rotation in radians.
+ Standard_NODISCARD gp_Ax2 Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const
+ {
+ gp_Ax2 aTemp = *this;
+ aTemp.Rotate (theA1, theAng);
+ return aTemp;
+ }
+
+ void Scale (const gp_Pnt& theP, const Standard_Real theS)
+ {
+ gp_Pnt aTemp = axis.Location();
+ aTemp.Scale (theP, theS);
+ axis.SetLocation (aTemp);
+ if (theS < 0.0)
+ {
+ vxdir.Reverse();
+ vydir.Reverse();
+ }
+ }
//! Applies a scaling transformation on the axis placement.
//! The "Location" point of the axisplacement is modified.
//! . the main direction of the axis placement is not changed.
//! . The "XDirection" and the "YDirection" are reversed.
//! So the axis placement stay right handed.
- Standard_NODISCARD gp_Ax2 Scaled (const gp_Pnt& P, const Standard_Real S) const;
-
- void Transform (const gp_Trsf& T);
-
+ Standard_NODISCARD gp_Ax2 Scaled (const gp_Pnt& theP, const Standard_Real theS) const
+ {
+ gp_Ax2 aTemp = *this;
+ aTemp.Scale (theP, theS);
+ return aTemp;
+ }
+
+ void Transform (const gp_Trsf& theT)
+ {
+ gp_Pnt aTemp = axis.Location();
+ aTemp.Transform (theT);
+ axis.SetLocation (aTemp);
+ vxdir.Transform (theT);
+ vydir.Transform (theT);
+ axis.SetDirection (vxdir.Crossed (vydir));
+ }
//! Transforms an axis placement with a Trsf.
- //! The "Location" point, the "XDirection" and the
- //! "YDirection" are transformed with T. The resulting
- //! main "Direction" of <me> is the cross product between
+ //! The "Location" point, the "XDirection" and the "YDirection" are transformed with theT.
+ //! The resulting main "Direction" of <me> is the cross product between
//! the "XDirection" and the "YDirection" after transformation.
- Standard_NODISCARD gp_Ax2 Transformed (const gp_Trsf& T) const;
-
- void Translate (const gp_Vec& V);
-
-
- //! Translates an axis plaxement in the direction of the vector
- //! <V>. The magnitude of the translation is the vector's magnitude.
- Standard_NODISCARD gp_Ax2 Translated (const gp_Vec& V) const;
-
- void Translate (const gp_Pnt& P1, const gp_Pnt& P2);
-
-
- //! Translates an axis placement from the point <P1> to the
- //! point <P2>.
- Standard_NODISCARD gp_Ax2 Translated (const gp_Pnt& P1, const gp_Pnt& P2) const;
-
+ Standard_NODISCARD gp_Ax2 Transformed (const gp_Trsf& theT) const
+ {
+ gp_Ax2 aTemp = *this;
+ aTemp.Transform (theT);
+ return aTemp;
+ }
+
+ void Translate (const gp_Vec& theV) { axis.Translate (theV); }
+
+ //! Translates an axis plaxement in the direction of the vector <theV>.
+ //! The magnitude of the translation is the vector's magnitude.
+ Standard_NODISCARD gp_Ax2 Translated (const gp_Vec& theV) const
+ {
+ gp_Ax2 aTemp = *this;
+ aTemp.Translate (theV);
+ return aTemp;
+ }
+
+ void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { axis.Translate (theP1, theP2); }
+
+ //! Translates an axis placement from the point <theP1> to the point <theP2>.
+ Standard_NODISCARD gp_Ax2 Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const
+ {
+ gp_Ax2 aTemp = *this;
+ aTemp.Translate (theP1, theP2);
+ return aTemp;
+ }
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
//! Inits the content of me from the stream
Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos);
-
-
-protected:
-
-
-
-
-
private:
-
-
gp_Ax1 axis;
gp_Dir vydir;
gp_Dir vxdir;
-
};
-
-#include <gp_Ax2.lxx>
-
-
-
-
+// =======================================================================
+// function : SetAxis
+// purpose :
+// =======================================================================
+inline void gp_Ax2::SetAxis (const gp_Ax1& theA1)
+{
+ Standard_Real a = theA1.Direction() * vxdir;
+ if (Abs(Abs(a) - 1.) <= Precision::Angular())
+ {
+ if (a > 0.)
+ {
+ vxdir = vydir;
+ vydir = axis.Direction();
+ axis = theA1;
+ }
+ else
+ {
+ vxdir = axis.Direction();
+ axis = theA1;
+ }
+ }
+ else
+ {
+ axis = theA1;
+ vxdir = axis.Direction().CrossCrossed (vxdir, axis.Direction());
+ vydir = axis.Direction().Crossed (vxdir);
+ }
+}
+
+// =======================================================================
+// function : SetDirection
+// purpose :
+// =======================================================================
+inline void gp_Ax2::SetDirection (const gp_Dir& theV)
+{
+ Standard_Real a = theV * vxdir;
+ if (Abs(Abs(a) - 1.) <= Precision::Angular())
+ {
+ if(a > 0.)
+ {
+ vxdir = vydir;
+ vydir = axis.Direction();
+ axis.SetDirection (theV);
+ }
+ else
+ {
+ vxdir = axis.Direction();
+ axis.SetDirection (theV);
+ }
+ }
+ else
+ {
+ axis.SetDirection (theV);
+ vxdir = theV.CrossCrossed (vxdir, theV);
+ vydir = theV.Crossed (vxdir);
+ }
+}
+
+// =======================================================================
+// function : IsCoplanar
+// purpose :
+// =======================================================================
+inline Standard_Boolean gp_Ax2::IsCoplanar (const gp_Ax2& theOther,
+ const Standard_Real theLinearTolerance,
+ const Standard_Real theAngularTolerance) const
+{
+ const gp_Dir& DD = axis.Direction();
+ const gp_Pnt& PP = axis.Location();
+ const gp_Pnt& OP = theOther.axis.Location();
+ Standard_Real D1 = (DD.X() * (OP.X() - PP.X())
+ + DD.Y() * (OP.Y() - PP.Y())
+ + DD.Z() * (OP.Z() - PP.Z()));
+ if (D1 < 0)
+ {
+ D1 = -D1;
+ }
+ return D1 <= theLinearTolerance
+ && axis.IsParallel (theOther.axis, theAngularTolerance);
+}
+
+// =======================================================================
+// function : IsCoplanar
+// purpose :
+// =======================================================================
+inline Standard_Boolean gp_Ax2::IsCoplanar (const gp_Ax1& theA,
+ const Standard_Real theLinearTolerance,
+ const Standard_Real theAngularTolerance) const
+{
+ const gp_Dir& DD = axis.Direction();
+ const gp_Pnt& PP = axis.Location();
+ const gp_Pnt& AP = theA.Location();
+ Standard_Real D1 = (DD.X() * (AP.X() - PP.X()) +
+ DD.Y() * (AP.Y() - PP.Y()) +
+ DD.Z() * (AP.Z() - PP.Z()));
+ if (D1 < 0)
+ {
+ D1 = -D1;
+ }
+ return D1 <= theLinearTolerance
+ && axis.IsNormal (theA, theAngularTolerance);
+}
#endif // _gp_Ax2_HeaderFile