0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / gp / gp_QuaternionNLerp.hxx
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 /**
20  * Class perform linear interpolation (approximate rotation interpolation),
21  * result quaternion nonunit, its length lay between. sqrt(2)/2  and 1.0
22  */
23 class gp_QuaternionNLerp
24 {
25
26 public:
27
28   gp_QuaternionNLerp() {}
29
30   gp_QuaternionNLerp (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 anInner = myQStart.Dot (myQEnd);
45     if (anInner < 0.0)
46     {
47       myQEnd = -myQEnd;
48     }
49     myQEnd -= myQStart;
50   }
51
52   //! Set interpolated quaternion for theT position (from 0.0 to 1.0)
53   void Interpolate (Standard_Real theT, gp_Quaternion& theResultQ) const
54   {
55     theResultQ = myQStart + myQEnd * theT;
56   }
57
58   static gp_Quaternion Interpolate (const gp_Quaternion& theQStart,
59                                     const gp_Quaternion& theQEnd,
60                                     Standard_Real theT)
61   {
62     gp_Quaternion aResultQ;
63     gp_QuaternionNLerp aNLerp (theQStart, theQEnd);
64     aNLerp.Interpolate (theT, aResultQ);
65     return aResultQ;
66   }
67
68 private:
69
70   gp_Quaternion myQStart;
71   gp_Quaternion myQEnd;
72
73 };
74
75 #endif //_gp_QuaternionNLerp_HeaderFile