Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _gp_QuaternionSLerp_HeaderFile
0015 #define _gp_QuaternionSLerp_HeaderFile
0016 
0017 #include <gp_Quaternion.hxx>
0018 
0019 //! Perform Spherical Linear Interpolation of the quaternions,
0020 //! return unit length quaternion.
0021 class gp_QuaternionSLerp
0022 {
0023 public:
0024 
0025   //! Compute interpolated quaternion between two quaternions.
0026   //! @param theStart first  quaternion
0027   //! @param theEnd   second quaternion
0028   //! @param theT normalized interpolation coefficient within 0..1 range,
0029   //!             with 0 pointing to theStart and 1 to theEnd.
0030   static gp_Quaternion Interpolate (const gp_Quaternion& theQStart,
0031                                     const gp_Quaternion& theQEnd,
0032                                     Standard_Real theT)
0033   {
0034     gp_Quaternion aResult;
0035     gp_QuaternionSLerp aLerp (theQStart, theQEnd);
0036     aLerp.Interpolate (theT, aResult);
0037     return aResult;
0038   }
0039 
0040 public:
0041 
0042   //! Empty constructor,
0043   gp_QuaternionSLerp() {}
0044 
0045   //! Constructor with initialization.
0046   gp_QuaternionSLerp (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
0047   {
0048     Init (theQStart, theQEnd);
0049   }
0050 
0051   //! Initialize the tool with Start and End values.
0052   void Init (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
0053   {
0054     InitFromUnit (theQStart.Normalized(), theQEnd.Normalized());
0055   }
0056 
0057   //! Initialize the tool with Start and End unit quaternions.
0058   void InitFromUnit (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
0059   {
0060     myQStart = theQStart;
0061     myQEnd   = theQEnd;
0062     Standard_Real cosOmega = myQStart.Dot (myQEnd);
0063     if (cosOmega < 0.0)
0064     {
0065       cosOmega = -cosOmega;
0066       myQEnd = -myQEnd;
0067     }
0068     if (cosOmega > 0.9999)
0069     {
0070       cosOmega = 0.9999;
0071     }
0072     myOmega = ACos (cosOmega);
0073     Standard_Real invSinOmega = (1.0 / Sin (myOmega));
0074     myQStart.Scale (invSinOmega);
0075     myQEnd.Scale (invSinOmega);
0076   }
0077 
0078   //! Set interpolated quaternion for theT position (from 0.0 to 1.0)
0079   void Interpolate (Standard_Real theT, gp_Quaternion& theResultQ) const
0080   {
0081     theResultQ = myQStart * Sin((1.0 - theT) * myOmega) + myQEnd * Sin (theT * myOmega);
0082   }
0083 
0084 private:
0085 
0086   gp_Quaternion myQStart;
0087   gp_Quaternion myQEnd;
0088   Standard_Real myOmega;
0089 
0090 };
0091 
0092 #endif //_gp_QuaternionSLerp_HeaderFile