0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / gp / gp_QuaternionSLerp.hxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14#ifndef _gp_QuaternionSLerp_HeaderFile
15#define _gp_QuaternionSLerp_HeaderFile
16
17#include <gp_Quaternion.hxx>
18
19/**
20 * Perform Spherical Linear Interpolation of the quaternions,
21 * return unit length quaternion.
22 */
23class gp_QuaternionSLerp
24{
25
26public:
27
28 gp_QuaternionSLerp() {}
29
30 gp_QuaternionSLerp (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
31 {
32 Init (theQStart, theQEnd);
33 }
34
35 void Init (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
36 {
37 InitFromUnit (theQStart.Normalized(), theQEnd.Normalized());
38 }
39
40 void InitFromUnit (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
41 {
42 myQStart = theQStart;
43 myQEnd = theQEnd;
44 Standard_Real cosOmega = myQStart.Dot (myQEnd);
45 if (cosOmega < 0.0)
46 {
47 cosOmega = -cosOmega;
48 myQEnd = -myQEnd;
49 }
50 if (cosOmega > 0.9999)
51 {
52 cosOmega = 0.9999;
53 }
54 myOmega = ACos (cosOmega);
55 Standard_Real invSinOmega = (1.0 / Sin (myOmega));
56 myQStart.Scale (invSinOmega);
57 myQEnd.Scale (invSinOmega);
58 }
59
60 //! Set interpolated quaternion for theT position (from 0.0 to 1.0)
61 void Interpolate (Standard_Real theT, gp_Quaternion& theResultQ) const
62 {
63 theResultQ = myQStart * Sin((1.0 - theT) * myOmega) + myQEnd * Sin (theT * myOmega);
64 }
65
66private:
67
68 gp_Quaternion myQStart;
69 gp_Quaternion myQEnd;
70 Standard_Real myOmega;
71
72};
73
74#endif //_gp_QuaternionSLerp_HeaderFile