Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:28:00

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