1 // Copyright (c) 1999-2014 OPEN CASCADE SAS 2 // 3 // This file is part of Open CASCADE Technology software library. 4 // 5 // This library is free software; you can redistribute it and/or modify it under 6 // the terms of the GNU Lesser General Public License version 2.1 as published 7 // by the Free Software Foundation, with special exception defined in the file 8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 9 // distribution for complete text of the license and disclaimer of any warranty. 10 // 11 // Alternatively, this file may be used under the terms of Open CASCADE 12 // commercial license or contractual agreement. 13 14 #ifndef _gp_QuaternionNLerp_HeaderFile 15 #define _gp_QuaternionNLerp_HeaderFile 16 17 #include <gp_Quaternion.hxx> 18 19 //! Class perform linear interpolation (approximate rotation interpolation), 20 //! result quaternion nonunit, its length lay between. sqrt(2)/2 and 1.0 21 class gp_QuaternionNLerp 22 { 23 public: 24 25 //! Compute interpolated quaternion between two quaternions. 26 //! @param theStart first quaternion 27 //! @param theEnd second quaternion 28 //! @param theT normalized interpolation coefficient within 0..1 range, 29 //! with 0 pointing to theStart and 1 to theEnd. Interpolate(const gp_Quaternion & theQStart,const gp_Quaternion & theQEnd,Standard_Real theT)30 static gp_Quaternion Interpolate (const gp_Quaternion& theQStart, 31 const gp_Quaternion& theQEnd, 32 Standard_Real theT) 33 { 34 gp_Quaternion aResult; 35 gp_QuaternionNLerp aLerp (theQStart, theQEnd); 36 aLerp.Interpolate (theT, aResult); 37 return aResult; 38 } 39 40 public: 41 42 //! Empty constructor, gp_QuaternionNLerp()43 gp_QuaternionNLerp() {} 44 45 //! Constructor with initialization. gp_QuaternionNLerp(const gp_Quaternion & theQStart,const gp_Quaternion & theQEnd)46 gp_QuaternionNLerp (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd) 47 { 48 Init (theQStart, theQEnd); 49 } 50 51 //! Initialize the tool with Start and End values. Init(const gp_Quaternion & theQStart,const gp_Quaternion & theQEnd)52 void Init (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd) 53 { 54 InitFromUnit (theQStart.Normalized(), theQEnd.Normalized()); 55 } 56 57 //! Initialize the tool with Start and End unit quaternions. InitFromUnit(const gp_Quaternion & theQStart,const gp_Quaternion & theQEnd)58 void InitFromUnit (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd) 59 { 60 myQStart = theQStart; 61 myQEnd = theQEnd; 62 Standard_Real anInner = myQStart.Dot (myQEnd); 63 if (anInner < 0.0) 64 { 65 myQEnd = -myQEnd; 66 } 67 myQEnd -= myQStart; 68 } 69 70 //! Set interpolated quaternion for theT position (from 0.0 to 1.0) Interpolate(Standard_Real theT,gp_Quaternion & theResultQ) const71 void Interpolate (Standard_Real theT, gp_Quaternion& theResultQ) const 72 { 73 theResultQ = myQStart + myQEnd * theT; 74 } 75 76 private: 77 78 gp_Quaternion myQStart; 79 gp_Quaternion myQEnd; 80 81 }; 82 83 #endif //_gp_QuaternionNLerp_HeaderFile 84