Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:44

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_Hypr_HeaderFile
0016 #define _gp_Hypr_HeaderFile
0017 
0018 #include <gp.hxx>
0019 #include <gp_Ax1.hxx>
0020 #include <gp_Ax2.hxx>
0021 #include <gp_Pnt.hxx>
0022 #include <Standard_DomainError.hxx>
0023 #include <Standard_ConstructionError.hxx>
0024 
0025 //! Describes a branch of a hyperbola in 3D space.
0026 //! A hyperbola is defined by its major and minor radii and
0027 //! positioned in space with a coordinate system (a gp_Ax2
0028 //! object) of which:
0029 //! -   the origin is the center of the hyperbola,
0030 //! -   the "X Direction" defines the major axis of the
0031 //! hyperbola, and
0032 //! - the "Y Direction" defines the minor axis of the hyperbola.
0033 //! The origin, "X Direction" and "Y Direction" of this
0034 //! coordinate system together define the plane of the
0035 //! hyperbola. This coordinate system is the "local
0036 //! coordinate system" of the hyperbola. In this coordinate
0037 //! system, the equation of the hyperbola is:
0038 //! X*X/(MajorRadius**2)-Y*Y/(MinorRadius**2) = 1.0
0039 //! The branch of the hyperbola described is the one located
0040 //! on the positive side of the major axis.
0041 //! The "main Direction" of the local coordinate system is a
0042 //! normal vector to the plane of the hyperbola. This vector
0043 //! gives an implicit orientation to the hyperbola. We refer to
0044 //! the "main Axis" of the local coordinate system as the
0045 //! "Axis" of the hyperbola.
0046 //! The following schema shows the plane of the hyperbola,
0047 //! and in it, the respective positions of the three branches of
0048 //! hyperbolas constructed with the functions OtherBranch,
0049 //! ConjugateBranch1, and ConjugateBranch2:
0050 //! @code
0051 //! ^YAxis
0052 //! |
0053 //! FirstConjugateBranch
0054 //! |
0055 //! Other            |                Main
0056 //! --------------------- C ------------------------------>XAxis
0057 //! Branch           |                Branch
0058 //! |
0059 //! |
0060 //! SecondConjugateBranch
0061 //! |                  ^YAxis
0062 //! @endcode
0063 //! Warning
0064 //! The major radius can be less than the minor radius.
0065 //! See Also
0066 //! gce_MakeHypr which provides functions for more
0067 //! complex hyperbola constructions
0068 //! Geom_Hyperbola which provides additional functions for
0069 //! constructing hyperbolas and works, in particular, with the
0070 //! parametric equations of hyperbolas
0071 class gp_Hypr 
0072 {
0073 public:
0074 
0075   DEFINE_STANDARD_ALLOC
0076 
0077   //! Creates of an indefinite hyperbola.
0078   gp_Hypr()
0079   : majorRadius (RealLast()),
0080     minorRadius (RealFirst())
0081   {}
0082 
0083   //! Creates a hyperbola with radius theMajorRadius and
0084   //! theMinorRadius, positioned in the space by the
0085   //! coordinate system theA2 such that:
0086   //! -   the origin of theA2 is the center of the hyperbola,
0087   //! -   the "X Direction" of theA2 defines the major axis of
0088   //! the hyperbola, that is, the major radius
0089   //! theMajorRadius is measured along this axis, and
0090   //! -   the "Y Direction" of theA2 defines the minor axis of
0091   //! the hyperbola, that is, the minor radius
0092   //! theMinorRadius is measured along this axis.
0093   //! Note: This class does not prevent the creation of a
0094   //! hyperbola where:
0095   //! -   theMajorAxis is equal to theMinorAxis, or
0096   //! -   theMajorAxis is less than theMinorAxis.
0097   //! Exceptions
0098   //! Standard_ConstructionError if theMajorAxis or theMinorAxis is negative.
0099   //! Raises ConstructionError if theMajorRadius < 0.0 or theMinorRadius < 0.0
0100   //! Raised if theMajorRadius < 0.0 or theMinorRadius < 0.0
0101   gp_Hypr (const gp_Ax2& theA2, const Standard_Real theMajorRadius, const Standard_Real theMinorRadius)
0102   : pos (theA2),
0103     majorRadius (theMajorRadius),
0104     minorRadius (theMinorRadius)
0105   {
0106     Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < 0.0,
0107       "gp_Hypr() - invalid construction parameters");
0108   }
0109 
0110   //! Modifies this hyperbola, by redefining its local coordinate
0111   //! system so that:
0112   //! -   its origin and "main Direction" become those of the
0113   //! axis theA1 (the "X Direction" and "Y Direction" are then
0114   //! recomputed in the same way as for any gp_Ax2).
0115   //! Raises ConstructionError if the direction of theA1 is parallel to the direction of
0116   //! the "XAxis" of the hyperbola.
0117   void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); }
0118 
0119   //! Modifies this hyperbola, by redefining its local coordinate
0120   //! system so that its origin becomes theP.
0121   void SetLocation (const gp_Pnt& theP) { pos = gp_Ax2 (theP, pos.Direction(), pos.XDirection()); }
0122 
0123   //! Modifies the major  radius of this hyperbola.
0124   //! Exceptions
0125   //! Standard_ConstructionError if theMajorRadius is negative.
0126   void SetMajorRadius (const Standard_Real theMajorRadius)
0127   {
0128     Standard_ConstructionError_Raise_if (theMajorRadius < 0.0,
0129       "gp_Hypr::SetMajorRadius() - major radius should be greater or equal zero");
0130     majorRadius = theMajorRadius;
0131   }
0132 
0133   //! Modifies the minor  radius of this hyperbola.
0134   //! Exceptions
0135   //! Standard_ConstructionError if theMinorRadius is negative.
0136   void SetMinorRadius (const Standard_Real theMinorRadius)
0137   {
0138     Standard_ConstructionError_Raise_if (theMinorRadius < 0.0,
0139       "gp_Hypr::SetMinorRadius() - minor radius should be greater or equal zero");
0140     minorRadius = theMinorRadius;
0141   }
0142 
0143   //! Modifies this hyperbola, by redefining its local coordinate
0144   //! system so that it becomes A2.
0145   void SetPosition (const gp_Ax2& theA2) { pos = theA2; }
0146 
0147   //! In the local coordinate system of the hyperbola the equation of
0148   //! the hyperbola is (X*X)/(A*A) - (Y*Y)/(B*B) = 1.0 and the
0149   //! equation of the first asymptote is Y = (B/A)*X
0150   //! where A is the major radius and B is the minor radius. Raises ConstructionError if MajorRadius = 0.0
0151   gp_Ax1 Asymptote1() const;
0152 
0153   //! In the local coordinate system of the hyperbola the equation of
0154   //! the hyperbola is (X*X)/(A*A) - (Y*Y)/(B*B) = 1.0 and the
0155   //! equation of the first asymptote is Y = -(B/A)*X.
0156   //! where A is the major radius and B is the minor radius. Raises ConstructionError if MajorRadius = 0.0
0157   gp_Ax1 Asymptote2() const;
0158 
0159   //! Returns the axis passing through the center,
0160   //! and normal to the plane of this hyperbola.
0161   const gp_Ax1& Axis() const { return pos.Axis(); }
0162 
0163   //! Computes the branch of hyperbola which is on the positive side of the
0164   //! "YAxis" of <me>.
0165   gp_Hypr ConjugateBranch1() const
0166   {
0167     return gp_Hypr (gp_Ax2 (pos.Location(), pos.Direction(), pos.YDirection()), minorRadius, majorRadius);
0168   }
0169 
0170   //! Computes the branch of hyperbola which is on the negative side of the
0171   //! "YAxis" of <me>.
0172   gp_Hypr ConjugateBranch2() const
0173   {
0174     gp_Dir aD = pos.YDirection();
0175     aD.Reverse();
0176     return gp_Hypr (gp_Ax2(pos.Location(), pos.Direction(), aD), minorRadius, majorRadius);
0177   }
0178 
0179   //! This directrix is the line normal to the XAxis of the hyperbola
0180   //! in the local plane (Z = 0) at a distance d = MajorRadius / e
0181   //! from the center of the hyperbola, where e is the eccentricity of
0182   //! the hyperbola.
0183   //! This line is parallel to the "YAxis". The intersection point
0184   //! between the directrix1 and the "XAxis" is the "Location" point
0185   //! of the directrix1. This point is on the positive side of the
0186   //! "XAxis".
0187   gp_Ax1 Directrix1() const;
0188 
0189   //! This line is obtained by the symmetrical transformation
0190   //! of "Directrix1" with respect to the "YAxis" of the hyperbola.
0191   gp_Ax1 Directrix2() const;
0192 
0193   //! Returns the eccentricity of the hyperbola (e > 1).
0194   //! If f is the distance between the location of the hyperbola
0195   //! and the Focus1 then the eccentricity e = f / MajorRadius. Raises DomainError if MajorRadius = 0.0
0196   Standard_Real Eccentricity() const
0197   {
0198     Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(),
0199       "gp_Hypr::Eccentricity() - major radius is zero");
0200     return sqrt (majorRadius * majorRadius + minorRadius * minorRadius) / majorRadius;
0201   }
0202 
0203   //! Computes the focal distance. It is the distance between the
0204   //! the two focus of the hyperbola.
0205   Standard_Real Focal() const
0206   {
0207     return 2.0 * sqrt (majorRadius * majorRadius + minorRadius * minorRadius);
0208   }
0209 
0210   //! Returns the first focus of the hyperbola. This focus is on the
0211   //! positive side of the "XAxis" of the hyperbola.
0212   gp_Pnt Focus1() const;
0213 
0214   //! Returns the second focus of the hyperbola. This focus is on the
0215   //! negative side of the "XAxis" of the hyperbola.
0216   gp_Pnt Focus2() const;
0217 
0218   //! Returns  the location point of the hyperbola. It is the
0219   //! intersection point between the "XAxis" and the "YAxis".
0220   const gp_Pnt& Location() const { return pos.Location(); }
0221 
0222   //! Returns the major radius of the hyperbola. It is the radius
0223   //! on the "XAxis" of the hyperbola.
0224   Standard_Real MajorRadius() const { return majorRadius; }
0225 
0226   //! Returns the minor radius of the hyperbola. It is the radius
0227   //! on the "YAxis" of the hyperbola.
0228   Standard_Real MinorRadius() const { return minorRadius; }
0229 
0230   //! Returns the branch of hyperbola obtained by doing the
0231   //! symmetrical transformation of <me> with respect to the
0232   //! "YAxis"  of <me>.
0233   gp_Hypr OtherBranch() const
0234   {
0235     gp_Dir aD = pos.XDirection();
0236     aD.Reverse();
0237     return gp_Hypr (gp_Ax2 (pos.Location(), pos.Direction(), aD), majorRadius, minorRadius);
0238   }
0239 
0240   //! Returns p = (e * e - 1) * MajorRadius where e is the
0241   //! eccentricity of the hyperbola.
0242   //! Raises DomainError if MajorRadius = 0.0
0243   Standard_Real Parameter() const
0244   {
0245     Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(),
0246                                    "gp_Hypr::Parameter() - major radius is zero");
0247     return (minorRadius * minorRadius) / majorRadius;
0248   }
0249 
0250   //! Returns the coordinate system of the hyperbola.
0251   const gp_Ax2& Position() const { return pos; }
0252 
0253   //! Computes an axis, whose
0254   //! -   the origin is the center of this hyperbola, and
0255   //! -   the unit vector is the "X Direction"
0256   //! of the local coordinate system of this hyperbola.
0257   //! These axes are, the major axis (the "X
0258   //! Axis") and  of this hyperboReturns the "XAxis" of the hyperbola.
0259   gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); }
0260 
0261   //! Computes an axis, whose
0262   //! -   the origin is the center of this hyperbola, and
0263   //! -   the unit vector is the "Y Direction"
0264   //! of the local coordinate system of this hyperbola.
0265   //! These axes are the minor axis (the "Y Axis") of this hyperbola
0266   gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); }
0267 
0268   Standard_EXPORT void Mirror (const gp_Pnt& theP);
0269 
0270   //! Performs the symmetrical transformation of an hyperbola with
0271   //! respect  to the point theP which is the center of the symmetry.
0272   Standard_NODISCARD Standard_EXPORT gp_Hypr Mirrored (const gp_Pnt& theP) const;
0273 
0274   Standard_EXPORT void Mirror (const gp_Ax1& theA1);
0275 
0276   //! Performs the symmetrical transformation of an hyperbola with
0277   //! respect to an axis placement which is the axis of the symmetry.
0278   Standard_NODISCARD Standard_EXPORT gp_Hypr Mirrored (const gp_Ax1& theA1) const;
0279 
0280   Standard_EXPORT void Mirror (const gp_Ax2& theA2);
0281 
0282   //! Performs the symmetrical transformation of an hyperbola with
0283   //! respect to a plane. The axis placement theA2 locates the plane
0284   //! of the symmetry (Location, XDirection, YDirection).
0285   Standard_NODISCARD Standard_EXPORT gp_Hypr Mirrored (const gp_Ax2& theA2) const;
0286 
0287   void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); }
0288 
0289   //! Rotates an hyperbola. theA1 is the axis of the rotation.
0290   //! theAng is the angular value of the rotation in radians.
0291   Standard_NODISCARD gp_Hypr Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const
0292   {
0293     gp_Hypr aH = *this;
0294     aH.pos.Rotate (theA1, theAng);
0295     return aH;
0296   }
0297 
0298   void Scale (const gp_Pnt& theP, const Standard_Real theS);
0299 
0300   //! Scales an hyperbola. theS is the scaling value.
0301   Standard_NODISCARD gp_Hypr Scaled (const gp_Pnt& theP, const Standard_Real theS) const;
0302 
0303   void Transform (const gp_Trsf& theT);
0304 
0305   //! Transforms an hyperbola with the transformation theT from
0306   //! class Trsf.
0307   Standard_NODISCARD gp_Hypr Transformed (const gp_Trsf& theT) const;
0308 
0309   void Translate (const gp_Vec& theV) { pos.Translate (theV); }
0310 
0311   //! Translates an hyperbola in the direction of the vector theV.
0312   //! The magnitude of the translation is the vector's magnitude.
0313   Standard_NODISCARD gp_Hypr Translated (const gp_Vec& theV) const
0314   {
0315     gp_Hypr aH = *this;
0316     aH.pos.Translate (theV);
0317     return aH;
0318   }
0319 
0320   void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); }
0321 
0322   //! Translates an hyperbola from the point theP1 to the point theP2.
0323   Standard_NODISCARD gp_Hypr Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const
0324   {
0325     gp_Hypr aH = *this;
0326     aH.pos.Translate (theP1, theP2);
0327     return aH;
0328   }
0329 
0330 private:
0331 
0332   gp_Ax2 pos;
0333   Standard_Real majorRadius;
0334   Standard_Real minorRadius;
0335 
0336 };
0337 
0338 //=======================================================================
0339 //function : Asymptote1
0340 // purpose :
0341 //=======================================================================
0342 inline gp_Ax1 gp_Hypr::Asymptote1() const
0343 {
0344   Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(),
0345                                        "gp_Hypr::Asymptote1() - major radius is zero");
0346   gp_Vec aV1 = gp_Vec (pos.YDirection());
0347   aV1.Multiply (minorRadius / majorRadius);
0348   gp_Vec aV = gp_Vec (pos.XDirection());
0349   aV.Add (aV1);
0350   return  gp_Ax1 (pos.Location(), gp_Dir (aV));
0351 }
0352 
0353 //=======================================================================
0354 //function : Asymptote2
0355 // purpose :
0356 //=======================================================================
0357 inline gp_Ax1 gp_Hypr::Asymptote2() const
0358 {
0359   Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(),
0360                                        "gp_Hypr::Asymptote1() - major radius is zero");
0361   gp_Vec aV1 = gp_Vec (pos.YDirection());
0362   aV1.Multiply (-minorRadius / majorRadius);
0363   gp_Vec aV = gp_Vec (pos.XDirection());
0364   aV.Add (aV1);
0365   return  gp_Ax1 ( pos.Location(), gp_Dir (aV));
0366 }
0367 
0368 //=======================================================================
0369 //function : Focus1
0370 // purpose :
0371 //=======================================================================
0372 inline gp_Pnt gp_Hypr::Focus1() const
0373 {
0374   Standard_Real aC = sqrt (majorRadius * majorRadius + minorRadius * minorRadius);
0375   const gp_Pnt& aPP = pos.Location  ();
0376   const gp_Dir& aDD = pos.XDirection();
0377   return gp_Pnt (aPP.X() + aC * aDD.X(),
0378                  aPP.Y() + aC * aDD.Y(),
0379                  aPP.Z() + aC * aDD.Z());
0380 }
0381 
0382 //=======================================================================
0383 //function : Focus2
0384 // purpose :
0385 //=======================================================================
0386 inline gp_Pnt gp_Hypr::Focus2 () const
0387 {
0388   Standard_Real aC = sqrt (majorRadius * majorRadius + minorRadius * minorRadius);
0389   const gp_Pnt& aPP = pos.Location  ();
0390   const gp_Dir& aDD = pos.XDirection();
0391   return gp_Pnt (aPP.X() - aC * aDD.X(),
0392                  aPP.Y() - aC * aDD.Y(),
0393                  aPP.Z() - aC * aDD.Z());
0394 }
0395 
0396 //=======================================================================
0397 //function : Scale
0398 // purpose :
0399 //=======================================================================
0400 inline void gp_Hypr::Scale (const gp_Pnt& theP,
0401                             const Standard_Real theS)
0402 {
0403   majorRadius *= theS;
0404   if (majorRadius < 0)
0405   {
0406     majorRadius = -majorRadius;
0407   }
0408   minorRadius *= theS;
0409   if (minorRadius < 0)
0410   {
0411     minorRadius = -minorRadius;
0412   }
0413   pos.Scale (theP, theS);
0414 }
0415 
0416 //=======================================================================
0417 //function : Scaled
0418 // purpose :
0419 //=======================================================================
0420 inline gp_Hypr gp_Hypr::Scaled (const gp_Pnt& theP,
0421                                 const Standard_Real theS) const
0422 {
0423   gp_Hypr aH = *this;
0424   aH.majorRadius *= theS;
0425   if (aH.majorRadius < 0)
0426   {
0427     aH.majorRadius = -aH.majorRadius;
0428   }
0429   aH.minorRadius *= theS;
0430   if (aH.minorRadius < 0)
0431   {
0432     aH.minorRadius = -aH.minorRadius;
0433   }
0434   aH.pos.Scale (theP, theS);
0435   return aH; 
0436 }
0437 
0438 //=======================================================================
0439 //function : Transform
0440 // purpose :
0441 //=======================================================================
0442 inline void gp_Hypr::Transform (const gp_Trsf& theT)
0443 { 
0444   majorRadius *= theT.ScaleFactor();
0445   if (majorRadius < 0)
0446   {
0447     majorRadius = -majorRadius;
0448   }
0449   minorRadius *= theT.ScaleFactor();
0450   if (minorRadius < 0)
0451   {
0452     minorRadius = -minorRadius;
0453   }
0454   pos.Transform (theT);
0455 }
0456 
0457 //=======================================================================
0458 //function : Transformed
0459 // purpose :
0460 //=======================================================================
0461 inline gp_Hypr gp_Hypr::Transformed (const gp_Trsf& theT) const
0462 {
0463   gp_Hypr aH = *this;
0464   aH.majorRadius *= theT.ScaleFactor();
0465   if (aH.majorRadius < 0)
0466   {
0467     aH.majorRadius = -aH.majorRadius;
0468   }
0469   aH.minorRadius *= theT.ScaleFactor();
0470   if (aH.minorRadius < 0)
0471   {
0472     aH.minorRadius = -aH.minorRadius;
0473   }
0474   aH.pos.Transform (theT);
0475   return aH; 
0476 }
0477 
0478 //=======================================================================
0479 //function : Directrix1
0480 // purpose :
0481 //=======================================================================
0482 inline gp_Ax1 gp_Hypr::Directrix1 () const
0483 {
0484   Standard_Real anE = Eccentricity();
0485   gp_XYZ anOrig = pos.XDirection().XYZ();
0486   anOrig.Multiply (majorRadius / anE);
0487   anOrig.Add (pos.Location().XYZ());
0488   return gp_Ax1 (gp_Pnt (anOrig), pos.YDirection());
0489 }
0490 
0491 //=======================================================================
0492 //function : Directrix2
0493 // purpose :
0494 //=======================================================================
0495 inline gp_Ax1 gp_Hypr::Directrix2 () const
0496 {
0497   Standard_Real anE = Eccentricity();
0498   gp_XYZ anOrig = pos.XDirection().XYZ();
0499   anOrig.Multiply (-majorRadius / anE);
0500   anOrig.Add (pos.Location().XYZ());
0501   return gp_Ax1 (gp_Pnt (anOrig), pos.YDirection());
0502 }
0503 
0504 #endif // _gp_Hypr_HeaderFile