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_Circ_HeaderFile
0016 #define _gp_Circ_HeaderFile
0017 
0018 #include <gp_Ax1.hxx>
0019 #include <gp_Ax2.hxx>
0020 #include <gp_Pnt.hxx>
0021 #include <gp_Trsf.hxx>
0022 #include <gp_Vec.hxx>
0023 #include <Standard_ConstructionError.hxx>
0024 
0025 //! Describes a circle in 3D space.
0026 //! A circle is defined by its radius and positioned in space
0027 //! with a coordinate system (a gp_Ax2 object) as follows:
0028 //! -   the origin of the coordinate system is the center of the circle, and
0029 //! -   the origin, "X Direction" and "Y Direction" of the
0030 //! coordinate system define the plane of the circle.
0031 //! This positioning coordinate system is the "local
0032 //! coordinate system" of the circle. Its "main Direction"
0033 //! gives the normal vector to the plane of the circle. The
0034 //! "main Axis" of the coordinate system is referred to as
0035 //! the "Axis" of the circle.
0036 //! Note: when a gp_Circ circle is converted into a
0037 //! Geom_Circle circle, some implicit properties of the
0038 //! circle are used explicitly:
0039 //! -   the "main Direction" of the local coordinate system
0040 //! gives an implicit orientation to the circle (and defines
0041 //! its trigonometric sense),
0042 //! -   this orientation corresponds to the direction in
0043 //! which parameter values increase,
0044 //! -   the starting point for parameterization is that of the
0045 //! "X Axis" of the local coordinate system (i.e. the "X Axis" of the circle).
0046 //! See Also
0047 //! gce_MakeCirc which provides functions for more complex circle constructions
0048 //! Geom_Circle which provides additional functions for
0049 //! constructing circles and works, in particular, with the
0050 //! parametric equations of circles
0051 class gp_Circ 
0052 {
0053 public:
0054 
0055   DEFINE_STANDARD_ALLOC
0056 
0057   //! Creates an indefinite circle.
0058   gp_Circ() : radius (RealLast())
0059   {}
0060 
0061   //! A2 locates the circle and gives its orientation in 3D space.
0062   //! Warnings :
0063   //! It is not forbidden to create a circle with theRadius = 0.0  Raises ConstructionError if theRadius < 0.0
0064   gp_Circ (const gp_Ax2& theA2, const Standard_Real theRadius)
0065   : pos (theA2),
0066     radius(theRadius)
0067   {
0068     Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ() - radius should be positive number");
0069   }
0070 
0071   //! Changes the main axis of the circle. It is the axis
0072   //! perpendicular to the plane of the circle.
0073   //! Raises ConstructionError if the direction of theA1
0074   //! is parallel to the "XAxis" of the circle.
0075   void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); }
0076 
0077   //! Changes the "Location" point (center) of the circle.
0078   void SetLocation (const gp_Pnt& theP) { pos.SetLocation (theP); }
0079 
0080   //! Changes the position of the circle.
0081   void SetPosition (const gp_Ax2& theA2) { pos = theA2; }
0082 
0083   //! Modifies the radius of this circle.
0084   //! Warning. This class does not prevent the creation of a circle where theRadius is null.
0085   //! Exceptions
0086   //! Standard_ConstructionError if theRadius is negative.
0087   void SetRadius (const Standard_Real theRadius)
0088   {
0089     Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ::SetRadius() - radius should be positive number");
0090     radius = theRadius;
0091   }
0092 
0093   //! Computes the area of the circle.
0094   Standard_Real Area() const { return M_PI * radius * radius; }
0095 
0096   //! Returns the main axis of the circle.
0097   //! It is the axis perpendicular to the plane of the circle,
0098   //! passing through the "Location" point (center) of the circle.
0099   const gp_Ax1& Axis() const { return pos.Axis(); }
0100 
0101   //! Computes the circumference of the circle.
0102   Standard_Real Length() const { return 2. * M_PI * radius; }
0103 
0104   //! Returns the center of the circle. It is the
0105   //! "Location" point of the local coordinate system
0106   //! of the circle
0107   const gp_Pnt& Location() const { return pos.Location(); }
0108 
0109   //! Returns the position of the circle.
0110   //! It is the local coordinate system of the circle.
0111   const gp_Ax2& Position() const { return pos; }
0112 
0113   //! Returns the radius of this circle.
0114   Standard_Real Radius() const { return radius; }
0115 
0116   //! Returns the "XAxis" of the circle.
0117   //! This axis is perpendicular to the axis of the conic.
0118   //! This axis and the "Yaxis" define the plane of the conic.
0119   gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); }
0120 
0121   //! Returns the "YAxis" of the circle.
0122   //! This axis and the "Xaxis" define the plane of the conic.
0123   //! The "YAxis" is perpendicular to the "Xaxis".
0124   gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); }
0125 
0126   //! Computes the minimum of distance between the point theP and
0127   //! any point on the circumference of the circle.
0128   Standard_Real Distance (const gp_Pnt& theP) const { return sqrt (SquareDistance (theP)); }
0129 
0130   //! Computes the square distance between <me> and the point theP.
0131   Standard_Real SquareDistance (const gp_Pnt& theP) const
0132   {
0133     gp_Vec aV (Location(), theP);
0134     Standard_Real aX = aV.Dot (pos.XDirection());
0135     Standard_Real anY = aV.Dot (pos.YDirection());
0136     Standard_Real aZ = aV.Dot (pos.Direction());
0137     Standard_Real aT = sqrt (aX * aX + anY * anY) - radius;
0138     return (aT * aT + aZ * aZ);
0139   }
0140 
0141   //! Returns True if the point theP is on the circumference.
0142   //! The distance between <me> and <theP> must be lower or
0143   //! equal to theLinearTolerance.
0144   Standard_Boolean Contains (const gp_Pnt& theP, const Standard_Real theLinearTolerance) const { return Distance (theP) <= theLinearTolerance; }
0145 
0146   Standard_EXPORT void Mirror (const gp_Pnt& theP);
0147 
0148   //! Performs the symmetrical transformation of a circle
0149   //! with respect to the point theP which is the center of the
0150   //! symmetry.
0151   Standard_NODISCARD Standard_EXPORT gp_Circ Mirrored (const gp_Pnt& theP) const;
0152 
0153   Standard_EXPORT void Mirror (const gp_Ax1& theA1);
0154 
0155   //! Performs the symmetrical transformation of a circle with
0156   //! respect to an axis placement which is the axis of the
0157   //! symmetry.
0158   Standard_NODISCARD Standard_EXPORT gp_Circ Mirrored (const gp_Ax1& theA1) const;
0159 
0160   Standard_EXPORT void Mirror (const gp_Ax2& theA2);
0161 
0162   //! Performs the symmetrical transformation of a circle with respect
0163   //! to a plane. The axis placement theA2 locates the plane of the
0164   //! of the symmetry : (Location, XDirection, YDirection).
0165   Standard_NODISCARD Standard_EXPORT gp_Circ Mirrored (const gp_Ax2& theA2) const;
0166 
0167   void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); }
0168 
0169   //! Rotates a circle. theA1 is the axis of the rotation.
0170   //! theAng is the angular value of the rotation in radians.
0171   Standard_NODISCARD gp_Circ Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const
0172   {
0173     gp_Circ aC = *this;
0174     aC.pos.Rotate (theA1, theAng);
0175     return aC;
0176   }
0177 
0178   void Scale (const gp_Pnt& theP, const Standard_Real theS);
0179 
0180   //! Scales a circle. theS is the scaling value.
0181   //! Warnings :
0182   //! If theS is negative the radius stay positive but
0183   //! the "XAxis" and the "YAxis" are  reversed as for
0184   //! an ellipse.
0185   Standard_NODISCARD gp_Circ Scaled (const gp_Pnt& theP, const Standard_Real theS) const;
0186 
0187   void Transform (const gp_Trsf& theT);
0188 
0189   //! Transforms a circle with the transformation theT from class Trsf.
0190   Standard_NODISCARD gp_Circ Transformed (const gp_Trsf& theT) const;
0191 
0192   void Translate (const gp_Vec& theV) { pos.Translate (theV); }
0193 
0194   //! Translates a circle in the direction of the vector theV.
0195   //! The magnitude of the translation is the vector's magnitude.
0196   Standard_NODISCARD gp_Circ Translated (const gp_Vec& theV) const
0197   {
0198     gp_Circ aC = *this;
0199     aC.pos.Translate (theV);
0200     return aC;
0201   }
0202 
0203   void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); }
0204 
0205   //! Translates a circle from the point theP1 to the point theP2.
0206   Standard_NODISCARD gp_Circ Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const
0207   {
0208     gp_Circ aC = *this;
0209     aC.pos.Translate (theP1, theP2);
0210     return aC;
0211   }
0212 
0213 private:
0214 
0215   gp_Ax2 pos;
0216   Standard_Real radius;
0217 
0218 };
0219 
0220 // =======================================================================
0221 // function : Scale
0222 // purpose  :
0223 // =======================================================================
0224 inline void gp_Circ::Scale (const gp_Pnt& theP, const Standard_Real theS)
0225 {
0226   radius *= theS;
0227   if (radius < 0)
0228   {
0229     radius = -radius;
0230   }
0231   pos.Scale (theP, theS);
0232 }
0233 
0234 // =======================================================================
0235 // function : Scaled
0236 // purpose  :
0237 // =======================================================================
0238 inline gp_Circ gp_Circ::Scaled (const gp_Pnt& theP, const Standard_Real theS) const
0239 {
0240   gp_Circ aC = *this;
0241   aC.radius *= theS;
0242   if (aC.radius < 0)
0243   {
0244     aC.radius = -aC.radius;
0245   }
0246   aC.pos.Scale (theP, theS);
0247   return aC;
0248 }
0249 
0250 // =======================================================================
0251 // function : Transform
0252 // purpose  :
0253 // =======================================================================
0254 inline void gp_Circ::Transform (const gp_Trsf& theT)
0255 {
0256   radius *= theT.ScaleFactor();
0257   if (radius < 0)
0258   {
0259     radius = -radius;
0260   }
0261   pos.Transform (theT);
0262 }
0263 
0264 // =======================================================================
0265 // function : Transformed
0266 // purpose  :
0267 // =======================================================================
0268 inline gp_Circ gp_Circ::Transformed (const gp_Trsf& theT) const
0269 {
0270   gp_Circ aC = *this;
0271   aC.radius *= theT.ScaleFactor();
0272   if (aC.radius < 0)
0273   {
0274     aC.radius = -aC.radius;
0275   }
0276   aC.pos.Transform (theT);
0277   return aC;
0278 }
0279 
0280 #endif // _gp_Circ_HeaderFile