Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-22 09:33:41

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_Parab_HeaderFile
0016 #define _gp_Parab_HeaderFile
0017 
0018 #include <gp_Ax1.hxx>
0019 #include <gp_Lin.hxx>
0020 #include <gp_Pnt.hxx>
0021 #include <Standard_ConstructionError.hxx>
0022 
0023 //! Describes a parabola in 3D space.
0024 //! A parabola is defined by its focal length (that is, the
0025 //! distance between its focus and apex) and positioned in
0026 //! space with a coordinate system (a gp_Ax2 object)
0027 //! where:
0028 //! -   the origin of the coordinate system is on the apex of
0029 //! the parabola,
0030 //! -   the "X Axis" of the coordinate system is the axis of
0031 //! symmetry; the parabola is on the positive side of this axis, and
0032 //! -   the origin, "X Direction" and "Y Direction" of the
0033 //! coordinate system define the plane of the parabola.
0034 //! The equation of the parabola in this coordinate system,
0035 //! which is the "local coordinate system" of the parabola, is:
0036 //! @code
0037 //! Y**2 = (2*P) * X.
0038 //! @endcode
0039 //! where P, referred to as the parameter of the parabola, is
0040 //! the distance between the focus and the directrix (P is
0041 //! twice the focal length).
0042 //! The "main Direction" of the local coordinate system gives
0043 //! the normal vector to the plane of the parabola.
0044 //! See Also
0045 //! gce_MakeParab which provides functions for more
0046 //! complex parabola constructions
0047 //! Geom_Parabola which provides additional functions for
0048 //! constructing parabolas and works, in particular, with the
0049 //! parametric equations of parabolas
0050 class gp_Parab
0051 {
0052 public:
0053   DEFINE_STANDARD_ALLOC
0054 
0055   //! Creates an indefinite Parabola.
0056   constexpr gp_Parab() noexcept
0057       : focalLength(RealLast())
0058   {
0059   }
0060 
0061   //! Creates a parabola with its local coordinate system "theA2"
0062   //! and it's focal length "Focal".
0063   //! The XDirection of theA2 defines the axis of symmetry of the
0064   //! parabola. The YDirection of theA2 is parallel to the directrix
0065   //! of the parabola. The Location point of theA2 is the vertex of
0066   //! the parabola
0067   //! Raises ConstructionError if theFocal < 0.0
0068   //! Raised if theFocal < 0.0
0069   constexpr gp_Parab(const gp_Ax2& theA2, const double theFocal)
0070       : pos(theA2),
0071         focalLength(theFocal)
0072   {
0073     Standard_ConstructionError_Raise_if(theFocal < 0.0, "gp_Parab() - focal length should be >= 0");
0074   }
0075 
0076   //! theD is the directrix of the parabola and theF the focus point.
0077   //! The symmetry axis (XAxis) of the parabola is normal to the
0078   //! directrix and pass through the focus point theF, but its
0079   //! location point is the vertex of the parabola.
0080   //! The YAxis of the parabola is parallel to theD and its location
0081   //! point is the vertex of the parabola. The normal to the plane
0082   //! of the parabola is the cross product between the XAxis and the
0083   //! YAxis.
0084   gp_Parab(const gp_Ax1& theD, const gp_Pnt& theF);
0085 
0086   //! Modifies this parabola by redefining its local coordinate system so that
0087   //! -   its origin and "main Direction" become those of the
0088   //! axis theA1 (the "X Direction" and "Y Direction" are then
0089   //! recomputed in the same way as for any gp_Ax2)
0090   //! Raises ConstructionError if the direction of theA1 is parallel to the previous
0091   //! XAxis of the parabola.
0092   void SetAxis(const gp_Ax1& theA1) { pos.SetAxis(theA1); }
0093 
0094   //! Changes the focal distance of the parabola.
0095   //! Raises ConstructionError if theFocal < 0.0
0096   void SetFocal(const double theFocal)
0097   {
0098     Standard_ConstructionError_Raise_if(theFocal < 0.0,
0099                                         "gp_Parab::SetFocal() - focal length should be >= 0");
0100     focalLength = theFocal;
0101   }
0102 
0103   //! Changes the location of the parabola. It is the vertex of
0104   //! the parabola.
0105   constexpr void SetLocation(const gp_Pnt& theP) noexcept { pos.SetLocation(theP); }
0106 
0107   //! Changes the local coordinate system of the parabola.
0108   constexpr void SetPosition(const gp_Ax2& theA2) noexcept { pos = theA2; }
0109 
0110   //! Returns the main axis of the parabola.
0111   //! It is the axis normal to the plane of the parabola passing
0112   //! through the vertex of the parabola.
0113   constexpr const gp_Ax1& Axis() const noexcept { return pos.Axis(); }
0114 
0115   //! Computes the directrix of this parabola.
0116   //! The directrix is:
0117   //! -   a line parallel to the "Y Direction" of the local
0118   //! coordinate system of this parabola, and
0119   //! -   located on the negative side of the axis of symmetry,
0120   //! at a distance from the apex which is equal to the focal
0121   //! length of this parabola.
0122   //! The directrix is returned as an axis (a gp_Ax1 object),
0123   //! the origin of which is situated on the "X Axis" of this parabola.
0124   gp_Ax1 Directrix() const;
0125 
0126   //! Returns the distance between the vertex and the focus
0127   //! of the parabola.
0128   constexpr double Focal() const noexcept { return focalLength; }
0129 
0130   //! -   Computes the focus of the parabola.
0131   gp_Pnt Focus() const;
0132 
0133   //! Returns the vertex of the parabola. It is the "Location"
0134   //! point of the coordinate system of the parabola.
0135   constexpr const gp_Pnt& Location() const noexcept { return pos.Location(); }
0136 
0137   //! Computes the parameter of the parabola.
0138   //! It is the distance between the focus and the directrix of
0139   //! the parabola. This distance is twice the focal length.
0140   constexpr double Parameter() const noexcept { return 2.0 * focalLength; }
0141 
0142   //! Returns the local coordinate system of the parabola.
0143   constexpr const gp_Ax2& Position() const noexcept { return pos; }
0144 
0145   //! Returns the symmetry axis of the parabola. The location point
0146   //! of the axis is the vertex of the parabola.
0147   constexpr gp_Ax1 XAxis() const noexcept { return gp_Ax1(pos.Location(), pos.XDirection()); }
0148 
0149   //! It is an axis parallel to the directrix of the parabola.
0150   //! The location point of this axis is the vertex of the parabola.
0151   constexpr gp_Ax1 YAxis() const noexcept { return gp_Ax1(pos.Location(), pos.YDirection()); }
0152 
0153   Standard_EXPORT void Mirror(const gp_Pnt& theP) noexcept;
0154 
0155   //! Performs the symmetrical transformation of a parabola
0156   //! with respect to the point theP which is the center of the
0157   //! symmetry.
0158   [[nodiscard]] Standard_EXPORT gp_Parab 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 parabola
0163   //! with respect to an axis placement which is the axis of
0164   //! the symmetry.
0165   [[nodiscard]] Standard_EXPORT gp_Parab Mirrored(const gp_Ax1& theA1) const;
0166 
0167   Standard_EXPORT void Mirror(const gp_Ax2& theA2);
0168 
0169   //! Performs the symmetrical transformation of a parabola
0170   //! with respect to a plane. The axis placement theA2 locates
0171   //! the plane of the symmetry (Location, XDirection, YDirection).
0172   [[nodiscard]] Standard_EXPORT gp_Parab 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 parabola. theA1 is the axis of the rotation.
0177   //! Ang is the angular value of the rotation in radians.
0178   [[nodiscard]] gp_Parab Rotated(const gp_Ax1& theA1, const double theAng) const
0179   {
0180     gp_Parab aPrb = *this;
0181     aPrb.pos.Rotate(theA1, theAng);
0182     return aPrb;
0183   }
0184 
0185   void Scale(const gp_Pnt& theP, const double theS);
0186 
0187   //! Scales a parabola. theS is the scaling value.
0188   //! If theS is negative the direction of the symmetry axis
0189   //! XAxis is reversed and the direction of the YAxis too.
0190   [[nodiscard]] gp_Parab Scaled(const gp_Pnt& theP, const double theS) const;
0191 
0192   void Transform(const gp_Trsf& theT);
0193 
0194   //! Transforms a parabola with the transformation theT from class Trsf.
0195   [[nodiscard]] gp_Parab Transformed(const gp_Trsf& theT) const;
0196 
0197   constexpr void Translate(const gp_Vec& theV) noexcept { pos.Translate(theV); }
0198 
0199   //! Translates a parabola in the direction of the vector theV.
0200   //! The magnitude of the translation is the vector's magnitude.
0201   [[nodiscard]] constexpr gp_Parab Translated(const gp_Vec& theV) const noexcept
0202   {
0203     gp_Parab aPrb = *this;
0204     aPrb.pos.Translate(theV);
0205     return aPrb;
0206   }
0207 
0208   constexpr void Translate(const gp_Pnt& theP1, const gp_Pnt& theP2) noexcept
0209   {
0210     pos.Translate(theP1, theP2);
0211   }
0212 
0213   //! Translates a parabola from the point theP1 to the point theP2.
0214   [[nodiscard]] constexpr gp_Parab Translated(const gp_Pnt& theP1,
0215                                               const gp_Pnt& theP2) const noexcept
0216   {
0217     gp_Parab aPrb = *this;
0218     aPrb.pos.Translate(theP1, theP2);
0219     return aPrb;
0220   }
0221 
0222 private:
0223   gp_Ax2 pos;
0224   double focalLength;
0225 };
0226 
0227 //=================================================================================================
0228 
0229 inline gp_Parab::gp_Parab(const gp_Ax1& theD, const gp_Pnt& theF)
0230 {
0231   gp_Lin aDroite(theD);
0232   focalLength        = aDroite.Distance(theF) / 2.;
0233   gp_Ax1        anAx = aDroite.Normal(theF).Position();
0234   gp_Ax1        anAy = aDroite.Position();
0235   const gp_Dir& aDD  = anAx.Direction();
0236   pos                = gp_Ax2(gp_Pnt(theF.X() - focalLength * aDD.X(),
0237                       theF.Y() - focalLength * aDD.Y(),
0238                       theF.Z() - focalLength * aDD.Z()),
0239                anAx.Direction().Crossed(anAy.Direction()),
0240                anAx.Direction());
0241 }
0242 
0243 //=================================================================================================
0244 
0245 inline gp_Ax1 gp_Parab::Directrix() const
0246 {
0247   const gp_Pnt& aPP = pos.Location();
0248   const gp_Dir& aDD = pos.XDirection();
0249   gp_Pnt        aP(aPP.X() - focalLength * aDD.X(),
0250             aPP.Y() - focalLength * aDD.Y(),
0251             aPP.Z() - focalLength * aDD.Z());
0252   return gp_Ax1(aP, pos.YDirection());
0253 }
0254 
0255 //=================================================================================================
0256 
0257 inline gp_Pnt gp_Parab::Focus() const
0258 {
0259   const gp_Pnt& aPP = pos.Location();
0260   const gp_Dir& aDD = pos.XDirection();
0261   return gp_Pnt(aPP.X() + focalLength * aDD.X(),
0262                 aPP.Y() + focalLength * aDD.Y(),
0263                 aPP.Z() + focalLength * aDD.Z());
0264 }
0265 
0266 //=================================================================================================
0267 
0268 inline void gp_Parab::Scale(const gp_Pnt& theP, const double theS)
0269 {
0270   focalLength *= theS;
0271   if (focalLength < 0)
0272   {
0273     focalLength = -focalLength;
0274   }
0275   pos.Scale(theP, theS);
0276 }
0277 
0278 //=================================================================================================
0279 
0280 inline gp_Parab gp_Parab::Scaled(const gp_Pnt& theP, const double theS) const
0281 {
0282   gp_Parab aPrb = *this;
0283   aPrb.focalLength *= theS;
0284   if (aPrb.focalLength < 0)
0285   {
0286     aPrb.focalLength = -aPrb.focalLength;
0287   }
0288   aPrb.pos.Scale(theP, theS);
0289   return aPrb;
0290 }
0291 
0292 //=================================================================================================
0293 
0294 inline void gp_Parab::Transform(const gp_Trsf& theT)
0295 {
0296   focalLength *= theT.ScaleFactor();
0297   if (focalLength < 0)
0298   {
0299     focalLength = -focalLength;
0300   }
0301   pos.Transform(theT);
0302 }
0303 
0304 //=================================================================================================
0305 
0306 inline gp_Parab gp_Parab::Transformed(const gp_Trsf& theT) const
0307 {
0308   gp_Parab aPrb = *this;
0309   aPrb.focalLength *= theT.ScaleFactor();
0310   if (aPrb.focalLength < 0)
0311   {
0312     aPrb.focalLength = -aPrb.focalLength;
0313   }
0314   aPrb.pos.Transform(theT);
0315   return aPrb;
0316 }
0317 
0318 #endif // _gp_Parab_HeaderFile