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_Circ2d_HeaderFile
0016 #define _gp_Circ2d_HeaderFile
0017 
0018 #include <gp_Ax22d.hxx>
0019 #include <gp_Ax2d.hxx>
0020 #include <gp_Pnt2d.hxx>
0021 #include <gp_Trsf2d.hxx>
0022 #include <gp_Vec2d.hxx>
0023 #include <Standard_ConstructionError.hxx>
0024 
0025 //! Describes a circle in the plane (2D space).
0026 //! A circle is defined by its radius and positioned in the
0027 //! plane with a coordinate system (a gp_Ax22d object) as follows:
0028 //! -   the origin of the coordinate system is the center of the circle, and
0029 //! -   the orientation (direct or indirect) of the coordinate
0030 //! system gives an implicit orientation to the circle (and
0031 //! defines its trigonometric sense).
0032 //! This positioning coordinate system is the "local
0033 //! coordinate system" of the circle.
0034 //! Note: when a gp_Circ2d circle is converted into a
0035 //! Geom2d_Circle circle, some implicit properties of the
0036 //! circle are used explicitly:
0037 //! -   the implicit orientation corresponds to the direction in
0038 //! which parameter values increase,
0039 //! -   the starting point for parameterization is that of the "X
0040 //! Axis" of the local coordinate system (i.e. the "X Axis" of the circle).
0041 //! See Also
0042 //! GccAna and Geom2dGcc packages which provide
0043 //! functions for constructing circles defined by geometric constraints
0044 //! gce_MakeCirc2d which provides functions for more
0045 //! complex circle constructions
0046 //! Geom2d_Circle which provides additional functions for
0047 //! constructing circles and works, with the parametric
0048 //! equations of circles in particular  gp_Ax22d
0049 class gp_Circ2d 
0050 {
0051 public:
0052 
0053   DEFINE_STANDARD_ALLOC
0054 
0055   //! creates an indefinite circle.
0056   gp_Circ2d()
0057   : radius  (RealLast())
0058   {}
0059 
0060   //! The location point of theXAxis is the center of the circle.
0061   //! Warnings :
0062   //! It is not forbidden to create a circle with theRadius = 0.0   Raises ConstructionError if theRadius < 0.0.
0063   //! Raised if theRadius < 0.0.
0064   gp_Circ2d (const gp_Ax2d& theXAxis, const Standard_Real theRadius, const Standard_Boolean theIsSense = Standard_True)
0065   : radius (theRadius)
0066   {
0067     Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ2d() - radius should be positive number");
0068     pos = gp_Ax22d (theXAxis, theIsSense);
0069   }
0070 
0071   //! theAxis defines the Xaxis and Yaxis of the circle which defines
0072   //! the origin and the sense of parametrization.
0073   //! The location point of theAxis is the center of the circle.
0074   //! Warnings :
0075   //! It is not forbidden to create a circle with theRadius = 0.0 Raises ConstructionError if theRadius < 0.0.
0076   //! Raised if theRadius < 0.0.
0077   gp_Circ2d (const gp_Ax22d& theAxis, const Standard_Real theRadius)
0078   : pos (theAxis),
0079     radius (theRadius)
0080   {
0081     Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ2d() - radius should be positive number");
0082   }
0083 
0084   //! Changes the location point (center) of the circle.
0085   void SetLocation (const gp_Pnt2d& theP) { pos.SetLocation (theP); }
0086 
0087   //! Changes the X axis of the circle.
0088   void SetXAxis (const gp_Ax2d& theA) { pos.SetXAxis (theA); }
0089 
0090   //! Changes the X axis of the circle.
0091   void SetAxis (const gp_Ax22d& theA) { pos.SetAxis (theA); }
0092 
0093   //! Changes the Y axis of the circle.
0094   void SetYAxis (const gp_Ax2d& theA) { pos.SetYAxis (theA); }
0095 
0096   //! Modifies the radius of this circle.
0097   //! This class does not prevent the creation of a circle where
0098   //! theRadius is null.
0099   //! Exceptions
0100   //! Standard_ConstructionError if theRadius is negative.
0101   void SetRadius (const Standard_Real theRadius)
0102   {
0103     Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ2d::SetRadius() - radius should be positive number");
0104     radius = theRadius;
0105   }
0106 
0107   //! Computes the area of the circle.
0108   Standard_Real Area() const { return M_PI * radius * radius; }
0109 
0110   //! Returns the normalized coefficients from the implicit equation
0111   //! of the circle :
0112   //! theA * (X**2) + theB * (Y**2) + 2*theC*(X*Y) + 2*theD*X + 2*theE*Y + theF = 0.0
0113   void Coefficients (Standard_Real& theA, Standard_Real& theB,
0114                      Standard_Real& theC, Standard_Real& theD,
0115                      Standard_Real& theE, Standard_Real& theF) const;
0116 
0117   //! Does <me> contain theP ?
0118   //! Returns True if the distance between theP and any point on
0119   //! the circumference of the circle is lower of equal to
0120   //! <theLinearTolerance>.
0121   Standard_Boolean Contains (const gp_Pnt2d& theP, const Standard_Real theLinearTolerance) const
0122   {
0123     return Distance (theP) <= theLinearTolerance;
0124   }
0125 
0126   //! Computes the minimum of distance between the point theP and any
0127   //! point on the circumference of the circle.
0128   Standard_Real Distance (const gp_Pnt2d& theP) const;
0129 
0130   //! Computes the square distance between <me> and the point theP.
0131   Standard_Real SquareDistance (const gp_Pnt2d& theP) const;
0132 
0133   //! computes the circumference of the circle.
0134   Standard_Real Length() const { return 2. * M_PI * radius; }
0135 
0136   //! Returns the location point (center) of the circle.
0137   const gp_Pnt2d& Location() const { return pos.Location(); }
0138 
0139   //! Returns the radius value of the circle.
0140   Standard_Real Radius() const { return radius; }
0141 
0142   //! returns the position of the circle.
0143   const gp_Ax22d& Axis() const { return pos; }
0144 
0145   //! returns the position of the circle. Idem Axis(me).
0146   const gp_Ax22d& Position() const { return pos; }
0147 
0148   //! returns the X axis of the circle.
0149   gp_Ax2d XAxis() const { return gp_Ax2d (pos.XAxis()); }
0150 
0151   //! Returns the Y axis of the circle.
0152   //! Reverses the direction of the circle.
0153   gp_Ax2d YAxis() const { return gp_Ax2d (pos.YAxis()); }
0154 
0155   //! Reverses the orientation of the local coordinate system
0156   //! of this circle (the "Y Direction" is reversed) and therefore
0157   //! changes the implicit orientation of this circle.
0158   //! Reverse assigns the result to this circle,
0159   void Reverse()
0160   {
0161     gp_Dir2d aTemp = pos.YDirection();
0162     aTemp.Reverse();
0163     pos.SetAxis (gp_Ax22d (pos.Location(), pos.XDirection(), aTemp));
0164   }
0165 
0166   //! Reverses the orientation of the local coordinate system
0167   //! of this circle (the "Y Direction" is reversed) and therefore
0168   //! changes the implicit orientation of this circle.
0169   //! Reversed creates a new circle.
0170   Standard_NODISCARD gp_Circ2d Reversed() const;
0171 
0172   //! Returns true if the local coordinate system is direct
0173   //! and false in the other case.
0174   Standard_Boolean IsDirect() const
0175   {
0176     return (pos.XDirection().Crossed (pos.YDirection())) >= 0.0;
0177   }
0178 
0179   Standard_EXPORT void Mirror (const gp_Pnt2d& theP);
0180 
0181   //! Performs the symmetrical transformation of a circle with respect
0182   //! to the point theP which is the center of the symmetry
0183   Standard_NODISCARD Standard_EXPORT gp_Circ2d Mirrored (const gp_Pnt2d& theP) const;
0184 
0185   Standard_EXPORT void Mirror (const gp_Ax2d& theA);
0186 
0187   //! Performs the symmetrical transformation of a circle with respect
0188   //! to an axis placement which is the axis of the symmetry.
0189   Standard_NODISCARD Standard_EXPORT gp_Circ2d Mirrored (const gp_Ax2d& theA) const;
0190 
0191   void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng)
0192   {
0193     pos.Rotate (theP, theAng);
0194   }
0195 
0196   //! Rotates a circle. theP is the center of the rotation.
0197   //! Ang is the angular value of the rotation in radians.
0198   Standard_NODISCARD gp_Circ2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const
0199   {
0200     gp_Circ2d aCirc = *this;
0201     aCirc.pos.Rotate (theP, theAng);
0202     return aCirc;
0203   }
0204 
0205   void Scale (const gp_Pnt2d& theP, const Standard_Real theS);
0206 
0207   //! Scales a circle. theS is the scaling value.
0208   //! Warnings :
0209   //! If theS is negative the radius stay positive but
0210   //! the "XAxis" and the "YAxis" are  reversed as for
0211   //! an ellipse.
0212   Standard_NODISCARD gp_Circ2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const;
0213 
0214   void Transform (const gp_Trsf2d& theT);
0215 
0216   //! Transforms a circle with the transformation theT from class Trsf2d.
0217   Standard_NODISCARD gp_Circ2d Transformed (const gp_Trsf2d& theT) const;
0218 
0219   void Translate (const gp_Vec2d& theV) { pos.Translate (theV); }
0220 
0221   //! Translates a circle in the direction of the vector theV.
0222   //! The magnitude of the translation is the vector's magnitude.
0223   Standard_NODISCARD gp_Circ2d Translated (const gp_Vec2d& theV) const
0224   {
0225     gp_Circ2d aCirc = *this;
0226     aCirc.pos.Translate (theV);
0227     return aCirc;
0228   }
0229 
0230   void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { pos.Translate (theP1, theP2); }
0231 
0232   //! Translates a circle from the point theP1 to the point theP2.
0233   Standard_NODISCARD gp_Circ2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const
0234   {
0235     gp_Circ2d aCirc = *this;
0236     aCirc.pos.Translate (theP1, theP2);
0237     return aCirc;
0238   }
0239 
0240 private:
0241 
0242   gp_Ax22d pos;
0243   Standard_Real radius;
0244 
0245 };
0246 
0247 // =======================================================================
0248 // function : Coefficients
0249 // purpose  :
0250 // =======================================================================
0251 inline void gp_Circ2d::Coefficients (Standard_Real& theA,
0252                                      Standard_Real& theB,
0253                                      Standard_Real& theC,
0254                                      Standard_Real& theD,
0255                                      Standard_Real& theE,
0256                                      Standard_Real& theF) const
0257 {
0258   Standard_Real aXc = pos.Location().X();
0259   Standard_Real anYc = pos.Location().Y();
0260   theA = 1.0;
0261   theB = 1.0;
0262   theC = 0.0;
0263   theD = - aXc;
0264   theE = - anYc;
0265   theF = aXc * aXc + anYc * anYc - radius * radius;
0266 }
0267 
0268 // =======================================================================
0269 // function : Distance
0270 // purpose  :
0271 // =======================================================================
0272 inline Standard_Real gp_Circ2d::Distance (const gp_Pnt2d& theP) const
0273 {
0274   gp_XY aCoord = theP.XY();
0275   aCoord.Subtract (pos.Location().XY());
0276   Standard_Real aD = radius - aCoord.Modulus();
0277   if (aD < 0)
0278   {
0279     aD = -aD;
0280   }
0281   return aD;
0282 }
0283 
0284 // =======================================================================
0285 // function : Reversed
0286 // purpose  :
0287 // =======================================================================
0288 inline gp_Circ2d gp_Circ2d::Reversed() const
0289 {
0290   gp_Circ2d aCirc = *this;
0291   gp_Dir2d aTemp = pos.YDirection();
0292   aTemp.Reverse();
0293   aCirc.pos.SetAxis (gp_Ax22d(pos.Location(), pos.XDirection(), aTemp));
0294   return aCirc;
0295 }
0296 
0297 // =======================================================================
0298 // function : SquareDistance
0299 // purpose  :
0300 // =======================================================================
0301 inline Standard_Real gp_Circ2d::SquareDistance (const gp_Pnt2d& theP) const
0302 {
0303   gp_XY aCoord = theP.XY();
0304   aCoord.Subtract (pos.Location().XY());
0305   Standard_Real aD = radius - aCoord.Modulus();
0306   return aD * aD;
0307 }
0308 
0309 // =======================================================================
0310 // function : Scale
0311 // purpose  :
0312 // =======================================================================
0313 inline void gp_Circ2d::Scale (const gp_Pnt2d& theP, const Standard_Real theS)
0314 {
0315   radius *= theS;
0316   if (radius < 0)
0317   {
0318     radius = -radius;
0319   }
0320   pos.Scale (theP, theS);
0321 }
0322 
0323 // =======================================================================
0324 // function : Scaled
0325 // purpose  :
0326 // =======================================================================
0327 inline gp_Circ2d gp_Circ2d::Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const
0328 {
0329   gp_Circ2d aCirc = *this;
0330   aCirc.radius *= theS;
0331   if (aCirc.radius < 0)
0332   {
0333     aCirc.radius = -aCirc.radius;
0334   }
0335   aCirc.pos.Scale (theP, theS);
0336   return aCirc;
0337 }
0338 
0339 // =======================================================================
0340 // function : Transform
0341 // purpose  :
0342 // =======================================================================
0343 inline void gp_Circ2d::Transform (const gp_Trsf2d& theT)
0344 {
0345   radius *= theT.ScaleFactor();
0346   if (radius < 0)
0347   {
0348     radius = -radius;
0349   }
0350   pos.Transform (theT);
0351 }
0352 
0353 // =======================================================================
0354 // function : Transformed
0355 // purpose  :
0356 // =======================================================================
0357 inline gp_Circ2d gp_Circ2d::Transformed (const gp_Trsf2d& theT) const
0358 {
0359   gp_Circ2d aCirc = *this;
0360   aCirc.radius *= theT.ScaleFactor();
0361   if (aCirc.radius < 0)
0362   {
0363     aCirc.radius = -aCirc.radius;
0364   }
0365   aCirc.pos.Transform (theT);
0366   return aCirc;
0367 }
0368 
0369 #endif // _gp_Circ2d_HeaderFile