Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/opencascade/gp_Elips.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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_Elips_HeaderFile
0016 #define _gp_Elips_HeaderFile
0017 
0018 #include <gp.hxx>
0019 #include <gp_Ax1.hxx>
0020 #include <gp_Ax2.hxx>
0021 #include <gp_Pnt.hxx>
0022 #include <Standard_ConstructionError.hxx>
0023 
0024 //! Describes an ellipse in 3D space.
0025 //! An ellipse is defined by its major and minor radii and
0026 //! positioned in space with a coordinate system (a gp_Ax2 object) as follows:
0027 //! -   the origin of the coordinate system is the center of the ellipse,
0028 //! -   its "X Direction" defines the major axis of the ellipse, and
0029 //! - its "Y Direction" defines the minor axis of the ellipse.
0030 //! Together, the origin, "X Direction" and "Y Direction" of
0031 //! this coordinate system define the plane of the ellipse.
0032 //! This coordinate system is the "local coordinate system"
0033 //! of the ellipse. In this coordinate system, the equation of
0034 //! the ellipse is:
0035 //! @code
0036 //! X*X / (MajorRadius**2) + Y*Y / (MinorRadius**2) = 1.0
0037 //! @endcode
0038 //! The "main Direction" of the local coordinate system gives
0039 //! the normal vector to the plane of the ellipse. This vector
0040 //! gives an implicit orientation to the ellipse (definition of the
0041 //! trigonometric sense). We refer to the "main Axis" of the
0042 //! local coordinate system as the "Axis" of the ellipse.
0043 //! See Also
0044 //! gce_MakeElips which provides functions for more
0045 //! complex ellipse constructions
0046 //! Geom_Ellipse which provides additional functions for
0047 //! constructing ellipses and works, in particular, with the
0048 //! parametric equations of ellipses
0049 class gp_Elips
0050 {
0051 public:
0052   DEFINE_STANDARD_ALLOC
0053 
0054   //! Creates an indefinite ellipse.
0055   constexpr gp_Elips() noexcept
0056       : majorRadius(RealLast()),
0057         minorRadius(RealSmall())
0058   {
0059   }
0060 
0061   //! The major radius of the ellipse is on the "XAxis" and the
0062   //! minor radius is on the "YAxis" of the ellipse. The "XAxis"
0063   //! is defined with the "XDirection" of theA2 and the "YAxis" is
0064   //! defined with the "YDirection" of theA2.
0065   //! Warnings :
0066   //! It is not forbidden to create an ellipse with theMajorRadius =
0067   //! theMinorRadius.
0068   //! Raises ConstructionError if theMajorRadius < theMinorRadius or theMinorRadius < 0.
0069   constexpr gp_Elips(const gp_Ax2& theA2, const double theMajorRadius, const double theMinorRadius)
0070       : pos(theA2),
0071         majorRadius(theMajorRadius),
0072         minorRadius(theMinorRadius)
0073   {
0074     Standard_ConstructionError_Raise_if(theMinorRadius < 0.0 || theMajorRadius < theMinorRadius,
0075                                         "gp_Elips() - invalid construction parameters");
0076   }
0077 
0078   //! Changes the axis normal to the plane of the ellipse.
0079   //! It modifies the definition of this plane.
0080   //! The "XAxis" and the "YAxis" are recomputed.
0081   //! The local coordinate system is redefined so that:
0082   //! -   its origin and "main Direction" become those of the
0083   //! axis theA1 (the "X Direction" and "Y Direction" are then
0084   //! recomputed in the same way as for any gp_Ax2), or
0085   //! Raises ConstructionError if the direction of theA1
0086   //! is parallel to the direction of the "XAxis" of the ellipse.
0087   void SetAxis(const gp_Ax1& theA1) { pos.SetAxis(theA1); }
0088 
0089   //! Modifies this ellipse, by redefining its local coordinate
0090   //! so that its origin becomes theP.
0091   constexpr void SetLocation(const gp_Pnt& theP) noexcept { pos.SetLocation(theP); }
0092 
0093   //! The major radius of the ellipse is on the "XAxis" (major axis)
0094   //! of the ellipse.
0095   //! Raises ConstructionError if theMajorRadius < MinorRadius.
0096   void SetMajorRadius(const double theMajorRadius)
0097   {
0098     Standard_ConstructionError_Raise_if(
0099       theMajorRadius < minorRadius,
0100       "gp_Elips::SetMajorRadius() - major radius should be greater or equal to minor radius");
0101     majorRadius = theMajorRadius;
0102   }
0103 
0104   //! The minor radius of the ellipse is on the "YAxis" (minor axis)
0105   //! of the ellipse.
0106   //! Raises ConstructionError if theMinorRadius > MajorRadius or MinorRadius < 0.
0107   void SetMinorRadius(const double theMinorRadius)
0108   {
0109     Standard_ConstructionError_Raise_if(theMinorRadius < 0.0 || majorRadius < theMinorRadius,
0110                                         "gp_Elips::SetMinorRadius() - minor radius should be a "
0111                                         "positive number lesser or equal to major radius");
0112     minorRadius = theMinorRadius;
0113   }
0114 
0115   //! Modifies this ellipse, by redefining its local coordinate
0116   //! so that it becomes theA2.
0117   constexpr void SetPosition(const gp_Ax2& theA2) noexcept { pos = theA2; }
0118 
0119   //! Computes the area of the Ellipse.
0120   constexpr double Area() const noexcept { return M_PI * majorRadius * minorRadius; }
0121 
0122   //! Computes the axis normal to the plane of the ellipse.
0123   constexpr const gp_Ax1& Axis() const noexcept { return pos.Axis(); }
0124 
0125   //! Computes the first or second directrix of this ellipse.
0126   //! These are the lines, in the plane of the ellipse, normal to
0127   //! the major axis, at a distance equal to
0128   //! MajorRadius/e from the center of the ellipse, where
0129   //! e is the eccentricity of the ellipse.
0130   //! The first directrix (Directrix1) is on the positive side of
0131   //! the major axis. The second directrix (Directrix2) is on
0132   //! the negative side.
0133   //! The directrix is returned as an axis (gp_Ax1 object), the
0134   //! origin of which is situated on the "X Axis" of the local
0135   //! coordinate system of this ellipse.
0136   //! Exceptions
0137   //! Standard_ConstructionError if the eccentricity is null
0138   //! (the ellipse has degenerated into a circle).
0139   gp_Ax1 Directrix1() const;
0140 
0141   //! This line is obtained by the symmetrical transformation
0142   //! of "Directrix1" with respect to the "YAxis" of the ellipse.
0143   //! Exceptions
0144   //! Standard_ConstructionError if the eccentricity is null
0145   //! (the ellipse has degenerated into a circle).
0146   gp_Ax1 Directrix2() const;
0147 
0148   //! Returns the eccentricity of the ellipse between 0.0 and 1.0
0149   //! If f is the distance between the center of the ellipse and
0150   //! the Focus1 then the eccentricity e = f / MajorRadius.
0151   //! Raises ConstructionError if MajorRadius = 0.0
0152   double Eccentricity() const;
0153 
0154   //! Computes the focal distance. It is the distance between the
0155   //! two focus focus1 and focus2 of the ellipse.
0156   double Focal() const { return 2.0 * sqrt(majorRadius * majorRadius - minorRadius * minorRadius); }
0157 
0158   //! Returns the first focus of the ellipse. This focus is on the
0159   //! positive side of the "XAxis" of the ellipse.
0160   gp_Pnt Focus1() const;
0161 
0162   //! Returns the second focus of the ellipse. This focus is on the
0163   //! negative side of the "XAxis" of the ellipse.
0164   gp_Pnt Focus2() const;
0165 
0166   //! Returns the center of the ellipse. It is the "Location"
0167   //! point of the coordinate system of the ellipse.
0168   constexpr const gp_Pnt& Location() const noexcept { return pos.Location(); }
0169 
0170   //! Returns the major radius of the ellipse.
0171   constexpr double MajorRadius() const noexcept { return majorRadius; }
0172 
0173   //! Returns the minor radius of the ellipse.
0174   constexpr double MinorRadius() const noexcept { return minorRadius; }
0175 
0176   //! Returns p = (1 - e * e) * MajorRadius where e is the eccentricity
0177   //! of the ellipse.
0178   //! Returns 0 if MajorRadius = 0
0179   double Parameter() const;
0180 
0181   //! Returns the coordinate system of the ellipse.
0182   constexpr const gp_Ax2& Position() const noexcept { return pos; }
0183 
0184   //! Returns the "XAxis" of the ellipse whose origin
0185   //! is the center of this ellipse. It is the major axis of the
0186   //! ellipse.
0187   constexpr gp_Ax1 XAxis() const noexcept { return gp_Ax1(pos.Location(), pos.XDirection()); }
0188 
0189   //! Returns the "YAxis" of the ellipse whose unit vector is the "X Direction" or the "Y Direction"
0190   //! of the local coordinate system of this ellipse.
0191   //! This is the minor axis of the ellipse.
0192   constexpr gp_Ax1 YAxis() const noexcept { return gp_Ax1(pos.Location(), pos.YDirection()); }
0193 
0194   Standard_EXPORT void Mirror(const gp_Pnt& theP) noexcept;
0195 
0196   //! Performs the symmetrical transformation of an ellipse with
0197   //! respect to the point theP which is the center of the symmetry.
0198   [[nodiscard]] Standard_EXPORT gp_Elips Mirrored(const gp_Pnt& theP) const noexcept;
0199 
0200   Standard_EXPORT void Mirror(const gp_Ax1& theA1);
0201 
0202   //! Performs the symmetrical transformation of an ellipse with
0203   //! respect to an axis placement which is the axis of the symmetry.
0204   [[nodiscard]] Standard_EXPORT gp_Elips Mirrored(const gp_Ax1& theA1) const;
0205 
0206   Standard_EXPORT void Mirror(const gp_Ax2& theA2);
0207 
0208   //! Performs the symmetrical transformation of an ellipse with
0209   //! respect to a plane. The axis placement theA2 locates the plane
0210   //! of the symmetry (Location, XDirection, YDirection).
0211   [[nodiscard]] Standard_EXPORT gp_Elips Mirrored(const gp_Ax2& theA2) const;
0212 
0213   void Rotate(const gp_Ax1& theA1, const double theAng) { pos.Rotate(theA1, theAng); }
0214 
0215   //! Rotates an ellipse. theA1 is the axis of the rotation.
0216   //! theAng is the angular value of the rotation in radians.
0217   [[nodiscard]] gp_Elips Rotated(const gp_Ax1& theA1, const double theAng) const
0218   {
0219     gp_Elips anE = *this;
0220     anE.pos.Rotate(theA1, theAng);
0221     return anE;
0222   }
0223 
0224   void Scale(const gp_Pnt& theP, const double theS);
0225 
0226   //! Scales an ellipse. theS is the scaling value.
0227   [[nodiscard]] gp_Elips Scaled(const gp_Pnt& theP, const double theS) const;
0228 
0229   void Transform(const gp_Trsf& theT);
0230 
0231   //! Transforms an ellipse with the transformation theT from class Trsf.
0232   [[nodiscard]] gp_Elips Transformed(const gp_Trsf& theT) const;
0233 
0234   constexpr void Translate(const gp_Vec& theV) noexcept { pos.Translate(theV); }
0235 
0236   //! Translates an ellipse in the direction of the vector theV.
0237   //! The magnitude of the translation is the vector's magnitude.
0238   [[nodiscard]] constexpr gp_Elips Translated(const gp_Vec& theV) const noexcept
0239   {
0240     gp_Elips anE = *this;
0241     anE.pos.Translate(theV);
0242     return anE;
0243   }
0244 
0245   constexpr void Translate(const gp_Pnt& theP1, const gp_Pnt& theP2) noexcept
0246   {
0247     pos.Translate(theP1, theP2);
0248   }
0249 
0250   //! Translates an ellipse from the point theP1 to the point theP2.
0251   [[nodiscard]] constexpr gp_Elips Translated(const gp_Pnt& theP1,
0252                                               const gp_Pnt& theP2) const noexcept
0253   {
0254     gp_Elips anE = *this;
0255     anE.pos.Translate(theP1, theP2);
0256     return anE;
0257   }
0258 
0259 private:
0260   gp_Ax2 pos;
0261   double majorRadius;
0262   double minorRadius;
0263 };
0264 
0265 //=================================================================================================
0266 
0267 inline gp_Ax1 gp_Elips::Directrix1() const
0268 {
0269   double anE = Eccentricity();
0270   Standard_ConstructionError_Raise_if(anE <= gp::Resolution(),
0271                                       "gp_Elips::Directrix1() - zero eccentricity");
0272   gp_XYZ anOrig = pos.XDirection().XYZ();
0273   anOrig.Multiply(majorRadius / anE);
0274   anOrig.Add(pos.Location().XYZ());
0275   return gp_Ax1(gp_Pnt(anOrig), pos.YDirection());
0276 }
0277 
0278 //=================================================================================================
0279 
0280 inline gp_Ax1 gp_Elips::Directrix2() const
0281 {
0282   double anE = Eccentricity();
0283   Standard_ConstructionError_Raise_if(anE <= gp::Resolution(),
0284                                       "gp_Elips::Directrix2() - zero eccentricity");
0285   gp_XYZ anOrig = pos.XDirection().XYZ();
0286   anOrig.Multiply(-majorRadius / anE);
0287   anOrig.Add(pos.Location().XYZ());
0288   return gp_Ax1(gp_Pnt(anOrig), pos.YDirection());
0289 }
0290 
0291 //=================================================================================================
0292 
0293 inline double gp_Elips::Eccentricity() const
0294 {
0295   if (majorRadius == 0.0)
0296   {
0297     return 0.0;
0298   }
0299   else
0300   {
0301     return sqrt(majorRadius * majorRadius - minorRadius * minorRadius) / majorRadius;
0302   }
0303 }
0304 
0305 //=================================================================================================
0306 
0307 inline gp_Pnt gp_Elips::Focus1() const
0308 {
0309   double        aC  = sqrt(majorRadius * majorRadius - minorRadius * minorRadius);
0310   const gp_Pnt& aPP = pos.Location();
0311   const gp_Dir& aDD = pos.XDirection();
0312   return gp_Pnt(aPP.X() + aC * aDD.X(), aPP.Y() + aC * aDD.Y(), aPP.Z() + aC * aDD.Z());
0313 }
0314 
0315 //=================================================================================================
0316 
0317 inline gp_Pnt gp_Elips::Focus2() const
0318 {
0319   double        aC  = sqrt(majorRadius * majorRadius - minorRadius * minorRadius);
0320   const gp_Pnt& aPP = pos.Location();
0321   const gp_Dir& aDD = pos.XDirection();
0322   return gp_Pnt(aPP.X() - aC * aDD.X(), aPP.Y() - aC * aDD.Y(), aPP.Z() - aC * aDD.Z());
0323 }
0324 
0325 //=================================================================================================
0326 
0327 inline double gp_Elips::Parameter() const
0328 {
0329   if (majorRadius == 0.0)
0330   {
0331     return 0.0;
0332   }
0333   else
0334   {
0335     return (minorRadius * minorRadius) / majorRadius;
0336   }
0337 }
0338 
0339 //=================================================================================================
0340 
0341 inline void gp_Elips::Scale(const gp_Pnt& theP, const double theS)
0342 //  Modified by skv - Fri Apr  8 10:28:10 2005 OCC8559 Begin
0343 // { pos.Scale(P, S); }
0344 {
0345   majorRadius *= theS;
0346   if (majorRadius < 0)
0347   {
0348     majorRadius = -majorRadius;
0349   }
0350   minorRadius *= theS;
0351   if (minorRadius < 0)
0352   {
0353     minorRadius = -minorRadius;
0354   }
0355   pos.Scale(theP, theS);
0356 }
0357 
0358 //  Modified by skv - Fri Apr  8 10:28:10 2005 OCC8559 End
0359 
0360 //=================================================================================================
0361 
0362 inline gp_Elips gp_Elips::Scaled(const gp_Pnt& theP, const double theS) const
0363 {
0364   gp_Elips anE = *this;
0365   anE.majorRadius *= theS;
0366   if (anE.majorRadius < 0)
0367   {
0368     anE.majorRadius = -anE.majorRadius;
0369   }
0370   anE.minorRadius *= theS;
0371   if (anE.minorRadius < 0)
0372   {
0373     anE.minorRadius = -anE.minorRadius;
0374   }
0375   anE.pos.Scale(theP, theS);
0376   return anE;
0377 }
0378 
0379 //=================================================================================================
0380 
0381 inline void gp_Elips::Transform(const gp_Trsf& theT)
0382 {
0383   majorRadius *= theT.ScaleFactor();
0384   if (majorRadius < 0)
0385   {
0386     majorRadius = -majorRadius;
0387   }
0388   minorRadius *= theT.ScaleFactor();
0389   if (minorRadius < 0)
0390   {
0391     minorRadius = -minorRadius;
0392   }
0393   pos.Transform(theT);
0394 }
0395 
0396 //=================================================================================================
0397 
0398 inline gp_Elips gp_Elips::Transformed(const gp_Trsf& theT) const
0399 {
0400   gp_Elips anE = *this;
0401   anE.majorRadius *= theT.ScaleFactor();
0402   if (anE.majorRadius < 0)
0403   {
0404     anE.majorRadius = -anE.majorRadius;
0405   }
0406   anE.minorRadius *= theT.ScaleFactor();
0407   if (anE.minorRadius < 0)
0408   {
0409     anE.minorRadius = -anE.minorRadius;
0410   }
0411   anE.pos.Transform(theT);
0412   return anE;
0413 }
0414 
0415 #endif // _gp_Elips_HeaderFile