1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 //=======================================================================
15 //function : gp_Quaternion
17 //=======================================================================
19 inline gp_Quaternion::gp_Quaternion()
20 : x(0.0), y(0.0), z(0.0), w(1.0)
24 //=======================================================================
25 //function : gp_Quaternion
27 //=======================================================================
29 inline gp_Quaternion::gp_Quaternion (const Standard_Real theX, const Standard_Real theY,
30 const Standard_Real theZ, const Standard_Real theW)
31 : x(theX), y(theY), z(theZ), w(theW)
35 //=======================================================================
36 //function : gp_Quaternion
38 //=======================================================================
40 inline gp_Quaternion::gp_Quaternion (const gp_Vec& theVecFrom, const gp_Vec& theVecTo)
42 SetRotation (theVecFrom, theVecTo);
45 //=======================================================================
46 //function : gp_Quaternion
48 //=======================================================================
50 inline gp_Quaternion::gp_Quaternion (const gp_Vec& theVecFrom, const gp_Vec& theVecTo, const gp_Vec& theHelpCrossVec)
52 SetRotation (theVecFrom, theVecTo, theHelpCrossVec);
55 //=======================================================================
56 //function : gp_Quaternion
58 //=======================================================================
60 inline gp_Quaternion::gp_Quaternion (const gp_Vec& theAxis, const Standard_Real theAngle)
62 SetVectorAndAngle (theAxis, theAngle);
65 //=======================================================================
66 //function : gp_Quaternion
68 //=======================================================================
70 inline gp_Quaternion::gp_Quaternion (const gp_Mat& theMat)
75 //=======================================================================
78 //=======================================================================
80 inline void gp_Quaternion::Set (Standard_Real theX, Standard_Real theY,
81 Standard_Real theZ, Standard_Real theW)
89 //=======================================================================
92 //=======================================================================
94 inline void gp_Quaternion::Set (const gp_Quaternion& theQuaternion)
102 //=======================================================================
105 //=======================================================================
107 inline Standard_Real gp_Quaternion::X() const
112 //=======================================================================
115 //=======================================================================
117 inline Standard_Real gp_Quaternion::Y() const
122 //=======================================================================
125 //=======================================================================
127 inline Standard_Real gp_Quaternion::Z() const
132 //=======================================================================
135 //=======================================================================
137 inline Standard_Real gp_Quaternion::W() const
142 //=======================================================================
143 //function : SetIdent
145 //=======================================================================
147 inline void gp_Quaternion::SetIdent()
153 //=======================================================================
156 //=======================================================================
158 inline void gp_Quaternion::Reverse()
165 //=======================================================================
166 //function : Reversed
168 //=======================================================================
170 inline gp_Quaternion gp_Quaternion::Reversed() const
172 return gp_Quaternion (-x, -y, -z, w);
175 //=======================================================================
178 //=======================================================================
180 inline void gp_Quaternion::Scale (const Standard_Real theScale)
188 //=======================================================================
191 //=======================================================================
193 inline gp_Quaternion gp_Quaternion::Scaled (const Standard_Real theScale) const
195 return gp_Quaternion (x * theScale, y * theScale, z * theScale, w * theScale);
198 //=======================================================================
199 //function : SquareNorm
201 //=======================================================================
203 inline Standard_Real gp_Quaternion::SquareNorm() const
205 return x * x + y * y + z * z + w * w;
208 //=======================================================================
211 //=======================================================================
213 inline Standard_Real gp_Quaternion::Norm() const
215 return Sqrt (SquareNorm());
218 //=======================================================================
221 //=======================================================================
223 inline void gp_Quaternion::Invert()
225 Standard_Real in = 1.0 / SquareNorm();
226 Set (-x * in, -y * in, -z * in, w * in);
229 //=======================================================================
230 //function : Inverted
232 //=======================================================================
234 inline gp_Quaternion gp_Quaternion::Inverted() const
236 Standard_Real in = 1.0 / SquareNorm();
237 return gp_Quaternion (-x * in, -y * in, -z * in, w * in);
240 //=======================================================================
241 //function : Normalized
243 //=======================================================================
245 inline gp_Quaternion gp_Quaternion::Normalized() const
247 gp_Quaternion aNormilizedQ (*this);
248 aNormilizedQ.Normalize();
252 //=======================================================================
255 //=======================================================================
257 inline gp_Quaternion gp_Quaternion::Negated () const
259 return gp_Quaternion (-x, -y, -z, -w);
262 //=======================================================================
265 //=======================================================================
267 inline gp_Quaternion gp_Quaternion::Added (const gp_Quaternion& theQ) const
269 return gp_Quaternion (x + theQ.x, y + theQ.y, z + theQ.z, w + theQ.w);
272 //=======================================================================
273 //function : Subtracted
275 //=======================================================================
277 inline gp_Quaternion gp_Quaternion::Subtracted (const gp_Quaternion& theQ) const
279 return gp_Quaternion (x - theQ.x, y - theQ.y, z - theQ.z, w - theQ.w);
282 //=======================================================================
283 //function : Multiplied
285 //=======================================================================
287 inline gp_Quaternion gp_Quaternion::Multiplied (const gp_Quaternion& theQ) const
289 return gp_Quaternion (w * theQ.x + x * theQ.w + y * theQ.z - z * theQ.y,
290 w * theQ.y + y * theQ.w + z * theQ.x - x * theQ.z,
291 w * theQ.z + z * theQ.w + x * theQ.y - y * theQ.x,
292 w * theQ.w - x * theQ.x - y * theQ.y - z * theQ.z);
293 // 16 multiplications 12 addidtions 0 variables
296 //=======================================================================
299 //=======================================================================
301 inline void gp_Quaternion::Add (const gp_Quaternion& theQ)
309 //=======================================================================
310 //function : Subtract
312 //=======================================================================
314 inline void gp_Quaternion::Subtract (const gp_Quaternion& theQ)
322 //=======================================================================
323 //function : Multiply
325 //=======================================================================
327 inline void gp_Quaternion::Multiply (const gp_Quaternion& theQ)
329 (*this) = Multiplied (theQ); // have no optimization here
332 //=======================================================================
335 //=======================================================================
337 inline Standard_Real gp_Quaternion::Dot (const gp_Quaternion& theQ) const
339 return x * theQ.x + y * theQ.y + z * theQ.z + w * theQ.w;