Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 09:13:34

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_QuaternionNLerp_HeaderFile
0015 #define _gp_QuaternionNLerp_HeaderFile
0016 
0017 #include <gp_Quaternion.hxx>
0018 
0019 //! Class perform linear interpolation (approximate rotation interpolation),
0020 //! result quaternion nonunit, its length lay between. sqrt(2)/2  and 1.0
0021 class gp_QuaternionNLerp
0022 {
0023 public:
0024   //! Compute interpolated quaternion between two quaternions.
0025   //! @param theStart first  quaternion
0026   //! @param theEnd   second quaternion
0027   //! @param theT normalized interpolation coefficient within 0..1 range,
0028   //!             with 0 pointing to theStart and 1 to theEnd.
0029   static gp_Quaternion Interpolate(const gp_Quaternion& theQStart,
0030                                    const gp_Quaternion& theQEnd,
0031                                    Standard_Real        theT)
0032   {
0033     gp_Quaternion      aResult;
0034     gp_QuaternionNLerp aLerp(theQStart, theQEnd);
0035     aLerp.Interpolate(theT, aResult);
0036     return aResult;
0037   }
0038 
0039 public:
0040   //! Empty constructor,
0041   gp_QuaternionNLerp() {}
0042 
0043   //! Constructor with initialization.
0044   gp_QuaternionNLerp(const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
0045   {
0046     Init(theQStart, theQEnd);
0047   }
0048 
0049   //! Initialize the tool with Start and End values.
0050   void Init(const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
0051   {
0052     InitFromUnit(theQStart.Normalized(), theQEnd.Normalized());
0053   }
0054 
0055   //! Initialize the tool with Start and End unit quaternions.
0056   void InitFromUnit(const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
0057   {
0058     myQStart              = theQStart;
0059     myQEnd                = theQEnd;
0060     Standard_Real anInner = myQStart.Dot(myQEnd);
0061     if (anInner < 0.0)
0062     {
0063       myQEnd = -myQEnd;
0064     }
0065     myQEnd -= myQStart;
0066   }
0067 
0068   //! Set interpolated quaternion for theT position (from 0.0 to 1.0)
0069   void Interpolate(Standard_Real theT, gp_Quaternion& theResultQ) const
0070   {
0071     theResultQ = myQStart + myQEnd * theT;
0072   }
0073 
0074 private:
0075   gp_Quaternion myQStart;
0076   gp_Quaternion myQEnd;
0077 };
0078 
0079 #endif //_gp_QuaternionNLerp_HeaderFile