OpenVDB  3.1.0
Quat.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2015 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 
31 #ifndef OPENVDB_MATH_QUAT_H_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_QUAT_H_HAS_BEEN_INCLUDED
33 
34 #include <iostream>
35 #include <cmath>
36 
37 #include "Mat.h"
38 #include "Mat3.h"
39 #include "Math.h"
40 #include "Vec3.h"
41 #include <openvdb/Exceptions.h>
42 
43 
44 namespace openvdb {
46 namespace OPENVDB_VERSION_NAME {
47 namespace math {
48 
49 template<typename T> class Quat;
50 
52 template <typename T>
53 Quat<T> slerp(const Quat<T> &q1, const Quat<T> &q2, T t, T tolerance=0.00001)
54 {
55  T qdot, angle, sineAngle;
56 
57  qdot = q1.dot(q2);
58 
59  if (fabs(qdot) >= 1.0) {
60  angle = 0; // not necessary but suppresses compiler warning
61  sineAngle = 0;
62  } else {
63  angle = acos(qdot);
64  sineAngle = sin(angle);
65  }
66 
67  //
68  // Denominator close to 0 corresponds to the case where the
69  // two quaternions are close to the same rotation. In this
70  // case linear interpolation is used but we normalize to
71  // guarantee unit length
72  //
73  if (sineAngle <= tolerance) {
74  T s = 1.0 - t;
75 
76  Quat<T> qtemp(s * q1[0] + t * q2[0], s * q1[1] + t * q2[1],
77  s * q1[2] + t * q2[2], s * q1[3] + t * q2[3]);
78  //
79  // Check the case where two close to antipodal quaternions were
80  // blended resulting in a nearly zero result which can happen,
81  // for example, if t is close to 0.5. In this case it is not safe
82  // to project back onto the sphere.
83  //
84  double lengthSquared = qtemp.dot(qtemp);
85 
86  if (lengthSquared <= tolerance * tolerance) {
87  qtemp = (t < 0.5) ? q1 : q2;
88  } else {
89  qtemp *= 1.0 / sqrt(lengthSquared);
90  }
91  return qtemp;
92  } else {
93 
94  T sine = 1.0 / sineAngle;
95  T a = sin((1.0 - t) * angle) * sine;
96  T b = sin(t * angle) * sine;
97  return Quat<T>(a * q1[0] + b * q2[0], a * q1[1] + b * q2[1],
98  a * q1[2] + b * q2[2], a * q1[3] + b * q2[3]);
99  }
100 
101 }
102 
103 template<typename T>
104 class Quat
105 {
106 public:
108  Quat() {}
109 
111  Quat(T x, T y, T z, T w)
112  {
113  mm[0] = x;
114  mm[1] = y;
115  mm[2] = z;
116  mm[3] = w;
117 
118  }
119 
121  Quat(T *a)
122  {
123  mm[0] = a[0];
124  mm[1] = a[1];
125  mm[2] = a[2];
126  mm[3] = a[3];
127 
128  }
129 
132  Quat(const Vec3<T> &axis, T angle)
133  {
134  // assert( REL_EQ(axis.length(), 1.) );
135 
136  T s = T(sin(angle*T(0.5)));
137 
138  mm[0] = axis.x() * s;
139  mm[1] = axis.y() * s;
140  mm[2] = axis.z() * s;
141 
142  mm[3] = T(cos(angle*T(0.5)));
143 
144  }
145 
148  {
149  T s = T(sin(angle*T(0.5)));
150 
151  mm[0] = (axis==math::X_AXIS) * s;
152  mm[1] = (axis==math::Y_AXIS) * s;
153  mm[2] = (axis==math::Z_AXIS) * s;
154 
155  mm[3] = T(cos(angle*T(0.5)));
156  }
157 
159  template<typename T1>
160  Quat(const Mat3<T1> &rot) {
161 
162  // verify that the matrix is really a rotation
163  if(!isUnitary(rot)) { // unitary is reflection or rotation
165  "A non-rotation matrix can not be used to construct a quaternion");
166  }
167  if (!isApproxEqual(rot.det(), (T1)1)) { // rule out reflection
169  "A reflection matrix can not be used to construct a quaternion");
170  }
171 
172  T trace = (T)rot.trace();
173  if (trace > 0) {
174 
175  T q_w = 0.5 * std::sqrt(trace+1);
176  T factor = 0.25 / q_w;
177 
178  mm[0] = factor * (rot(1,2) - rot(2,1));
179  mm[1] = factor * (rot(2,0) - rot(0,2));
180  mm[2] = factor * (rot(0,1) - rot(1,0));
181  mm[3] = q_w;
182  } else if (rot(0,0) > rot(1,1) && rot(0,0) > rot(2,2)) {
183 
184  T q_x = 0.5 * sqrt(rot(0,0)- rot(1,1)-rot(2,2)+1);
185  T factor = 0.25 / q_x;
186 
187  mm[0] = q_x;
188  mm[1] = factor * (rot(0,1) + rot(1,0));
189  mm[2] = factor * (rot(2,0) + rot(0,2));
190  mm[3] = factor * (rot(1,2) - rot(2,1));
191  } else if (rot(1,1) > rot(2,2)) {
192 
193  T q_y = 0.5 * sqrt(rot(1,1)-rot(0,0)-rot(2,2)+1);
194  T factor = 0.25 / q_y;
195 
196  mm[0] = factor * (rot(0,1) + rot(1,0));
197  mm[1] = q_y;
198  mm[2] = factor * (rot(1,2) + rot(2,1));
199  mm[3] = factor * (rot(2,0) - rot(0,2));
200  } else {
201 
202  T q_z = 0.5 * sqrt(rot(2,2)-rot(0,0)-rot(1,1)+1);
203  T factor = 0.25 / q_z;
204 
205  mm[0] = factor * (rot(2,0) + rot(0,2));
206  mm[1] = factor * (rot(1,2) + rot(2,1));
207  mm[2] = q_z;
208  mm[3] = factor * (rot(0,1) - rot(1,0));
209  }
210  }
211 
213  Quat(const Quat &q)
214  {
215  mm[0] = q.mm[0];
216  mm[1] = q.mm[1];
217  mm[2] = q.mm[2];
218  mm[3] = q.mm[3];
219 
220  }
221 
223  T& x() { return mm[0]; }
224  T& y() { return mm[1]; }
225  T& z() { return mm[2]; }
226  T& w() { return mm[3]; }
227 
229  T x() const { return mm[0]; }
230  T y() const { return mm[1]; }
231  T z() const { return mm[2]; }
232  T w() const { return mm[3]; }
233 
234  // Number of elements
235  static unsigned numElements() { return 4; }
236 
238  T& operator[](int i) { return mm[i]; }
239 
241  T operator[](int i) const { return mm[i]; }
242 
244  operator T*() { return mm; }
245  operator const T*() const { return mm; }
246 
248  T& operator()(int i) { return mm[i]; }
249 
251  T operator()(int i) const { return mm[i]; }
252 
254  T angle() const
255  {
256  T sqrLength = mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2];
257 
258  if ( sqrLength > 1.0e-8 ) {
259 
260  return T(T(2.0) * acos(mm[3]));
261 
262  } else {
263 
264  return T(0.0);
265  }
266  }
267 
269  Vec3<T> axis() const
270  {
271  T sqrLength = mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2];
272 
273  if ( sqrLength > 1.0e-8 ) {
274 
275  T invLength = T(T(1)/sqrt(sqrLength));
276 
277  return Vec3<T>( mm[0]*invLength, mm[1]*invLength, mm[2]*invLength );
278  } else {
279 
280  return Vec3<T>(1,0,0);
281  }
282  }
283 
284 
286  Quat& init(T x, T y, T z, T w)
287  {
288  mm[0] = x; mm[1] = y; mm[2] = z; mm[3] = w;
289  return *this;
290  }
291 
293  Quat& init() { return setIdentity(); }
294 
297  Quat& setAxisAngle(const Vec3<T>& axis, T angle)
298  {
299 
300  T s = T(sin(angle*T(0.5)));
301 
302  mm[0] = axis.x() * s;
303  mm[1] = axis.y() * s;
304  mm[2] = axis.z() * s;
305 
306  mm[3] = T(cos(angle*T(0.5)));
307 
308  return *this;
309  } // axisAngleTest
310 
313  {
314  mm[0] = mm[1] = mm[2] = mm[3] = 0;
315  return *this;
316  }
317 
320  {
321  mm[0] = mm[1] = mm[2] = 0;
322  mm[3] = 1;
323  return *this;
324  }
325 
327  Vec3<T> eulerAngles(RotationOrder rotationOrder) const
328  { return math::eulerAngles(Mat3<T>(*this), rotationOrder); }
329 
331  Quat& operator=(const Quat &q)
332  {
333  mm[0] = q.mm[0];
334  mm[1] = q.mm[1];
335  mm[2] = q.mm[2];
336  mm[3] = q.mm[3];
337 
338  return *this;
339  }
340 
342  bool operator==(const Quat &q) const
343  {
344  return (isExactlyEqual(mm[0],q.mm[0]) &&
345  isExactlyEqual(mm[1],q.mm[1]) &&
346  isExactlyEqual(mm[2],q.mm[2]) &&
347  isExactlyEqual(mm[3],q.mm[3]) );
348  }
349 
351  bool eq(const Quat &q, T eps=1.0e-7) const
352  {
353  return isApproxEqual(mm[0],q.mm[0],eps) && isApproxEqual(mm[1],q.mm[1],eps) &&
354  isApproxEqual(mm[2],q.mm[2],eps) && isApproxEqual(mm[3],q.mm[3],eps) ;
355  } // trivial
356 
358  Quat& operator+=(const Quat &q)
359  {
360  mm[0] += q.mm[0];
361  mm[1] += q.mm[1];
362  mm[2] += q.mm[2];
363  mm[3] += q.mm[3];
364 
365  return *this;
366  }
367 
369  Quat& operator-=(const Quat &q)
370  {
371  mm[0] -= q.mm[0];
372  mm[1] -= q.mm[1];
373  mm[2] -= q.mm[2];
374  mm[3] -= q.mm[3];
375 
376  return *this;
377  }
378 
380  Quat& operator*=(T scalar)
381  {
382  mm[0] *= scalar;
383  mm[1] *= scalar;
384  mm[2] *= scalar;
385  mm[3] *= scalar;
386 
387  return *this;
388  }
389 
391  Quat operator+(const Quat &q) const
392  {
393  return Quat<T>(mm[0]+q.mm[0], mm[1]+q.mm[1], mm[2]+q.mm[2], mm[3]+q.mm[3]);
394  }
395 
397  Quat operator-(const Quat &q) const
398  {
399  return Quat<T>(mm[0]-q.mm[0], mm[1]-q.mm[1], mm[2]-q.mm[2], mm[3]-q.mm[3]);
400  }
401 
403  Quat operator*(const Quat &q) const
404  {
405  Quat<T> prod;
406 
407  prod.mm[0] = mm[3]*q.mm[0] + mm[0]*q.mm[3] + mm[1]*q.mm[2] - mm[2]*q.mm[1];
408  prod.mm[1] = mm[3]*q.mm[1] + mm[1]*q.mm[3] + mm[2]*q.mm[0] - mm[0]*q.mm[2];
409  prod.mm[2] = mm[3]*q.mm[2] + mm[2]*q.mm[3] + mm[0]*q.mm[1] - mm[1]*q.mm[0];
410  prod.mm[3] = mm[3]*q.mm[3] - mm[0]*q.mm[0] - mm[1]*q.mm[1] - mm[2]*q.mm[2];
411 
412  return prod;
413 
414  }
415 
417  Quat operator*=(const Quat &q)
418  {
419  *this = *this * q;
420  return *this;
421  }
422 
424  Quat operator*(T scalar) const
425  {
426  return Quat<T>(mm[0]*scalar, mm[1]*scalar, mm[2]*scalar, mm[3]*scalar);
427  }
428 
430  Quat operator/(T scalar) const
431  {
432  return Quat<T>(mm[0]/scalar, mm[1]/scalar, mm[2]/scalar, mm[3]/scalar);
433  }
434 
436  Quat operator-() const
437  { return Quat<T>(-mm[0], -mm[1], -mm[2], -mm[3]); }
438 
441  Quat& add(const Quat &q1, const Quat &q2)
442  {
443  mm[0] = q1.mm[0] + q2.mm[0];
444  mm[1] = q1.mm[1] + q2.mm[1];
445  mm[2] = q1.mm[2] + q2.mm[2];
446  mm[3] = q1.mm[3] + q2.mm[3];
447 
448  return *this;
449  }
450 
453  Quat& sub(const Quat &q1, const Quat &q2)
454  {
455  mm[0] = q1.mm[0] - q2.mm[0];
456  mm[1] = q1.mm[1] - q2.mm[1];
457  mm[2] = q1.mm[2] - q2.mm[2];
458  mm[3] = q1.mm[3] - q2.mm[3];
459 
460  return *this;
461  }
462 
465  Quat& mult(const Quat &q1, const Quat &q2)
466  {
467  mm[0] = q1.mm[3]*q2.mm[0] + q1.mm[0]*q2.mm[3] +
468  q1.mm[1]*q2.mm[2] - q1.mm[2]*q2.mm[1];
469  mm[1] = q1.mm[3]*q2.mm[1] + q1.mm[1]*q2.mm[3] +
470  q1.mm[2]*q2.mm[0] - q1.mm[0]*q2.mm[2];
471  mm[2] = q1.mm[3]*q2.mm[2] + q1.mm[2]*q2.mm[3] +
472  q1.mm[0]*q2.mm[1] - q1.mm[1]*q2.mm[0];
473  mm[3] = q1.mm[3]*q2.mm[3] - q1.mm[0]*q2.mm[0] -
474  q1.mm[1]*q2.mm[1] - q1.mm[2]*q2.mm[2];
475 
476  return *this;
477  }
478 
481  Quat& scale(T scale, const Quat &q)
482  {
483  mm[0] = scale * q.mm[0];
484  mm[1] = scale * q.mm[1];
485  mm[2] = scale * q.mm[2];
486  mm[3] = scale * q.mm[3];
487 
488  return *this;
489  }
490 
492  T dot(const Quat &q) const
493  {
494  return (mm[0]*q.mm[0] + mm[1]*q.mm[1] + mm[2]*q.mm[2] + mm[3]*q.mm[3]);
495  }
496 
499  Quat derivative(const Vec3<T>& omega) const
500  {
501  return Quat<T>( +w()*omega.x() -z()*omega.y() +y()*omega.z() ,
502  +z()*omega.x() +w()*omega.y() -x()*omega.z() ,
503  -y()*omega.x() +x()*omega.y() +w()*omega.z() ,
504  -x()*omega.x() -y()*omega.y() -z()*omega.z() );
505  }
506 
508  bool normalize(T eps = T(1.0e-8))
509  {
510  T d = T(sqrt(mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2] + mm[3]*mm[3]));
511  if( isApproxEqual(d, T(0.0), eps) ) return false;
512  *this *= ( T(1)/d );
513  return true;
514  }
515 
517  Quat unit() const
518  {
519  T d = sqrt(mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2] + mm[3]*mm[3]);
520  if( isExactlyEqual(d , T(0.0) ) )
522  "Normalizing degenerate quaternion");
523  return *this / d;
524  }
525 
527  Quat inverse(T tolerance = T(0))
528  {
529  T d = mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2] + mm[3]*mm[3];
530  if( isApproxEqual(d, T(0.0), tolerance) )
532  "Cannot invert degenerate quaternion");
533  Quat result = *this/-d;
534  result.mm[3] = -result.mm[3];
535  return result;
536  }
537 
538 
541  Quat conjugate() const
542  {
543  return Quat<T>(-mm[0], -mm[1], -mm[2], mm[3]);
544  }
545 
547  Vec3<T> rotateVector(const Vec3<T> &v) const
548  {
549  Mat3<T> m(*this);
550  return m.transform(v);
551  }
552 
554  static Quat zero() { return Quat<T>(0,0,0,0); }
555  static Quat identity() { return Quat<T>(0,0,0,1); }
556 
558  std::string
559  str() const {
560  std::ostringstream buffer;
561 
562  buffer << "[";
563 
564  // For each column
565  for (unsigned j(0); j < 4; j++) {
566  if (j) buffer << ", ";
567  buffer << mm[j];
568  }
569 
570  buffer << "]";
571 
572  return buffer.str();
573  }
574 
576  friend std::ostream& operator<<(std::ostream &stream, const Quat &q)
577  {
578  stream << q.str();
579  return stream;
580  }
581 
582  friend Quat slerp<>(const Quat &q1, const Quat &q2, T t, T tolerance);
583 
584 
585  void write(std::ostream& os) const {
586  os.write((char*)&mm, sizeof(T)*4);
587  }
588  void read(std::istream& is) {
589  is.read((char*)&mm, sizeof(T)*4);
590  }
591 
592 protected:
593  T mm[4];
594 };
595 
597 template <typename S, typename T>
598 Quat<T> operator*(S scalar, const Quat<T> &q) { return q*scalar; }
599 
600 
604 template <typename T, typename T0>
605 Mat3<T> slerp(const Mat3<T0> &m1, const Mat3<T0> &m2, T t)
606 {
607  typedef Mat3<T> MatType;
608 
609  Quat<T> q1(m1);
610  Quat<T> q2(m2);
611 
612  if (q1.dot(q2) < 0) q2 *= -1;
613 
614  Quat<T> qslerp = slerp<T>(q1, q2, static_cast<T>(t));
615  MatType m = rotation<MatType>(qslerp);
616  return m;
617 }
618 
619 
620 
629 template <typename T, typename T0>
630 Mat3<T> bezLerp(const Mat3<T0> &m1, const Mat3<T0> &m2,
631  const Mat3<T0> &m3, const Mat3<T0> &m4,
632  T t)
633 {
634  Mat3<T> m00, m01, m02, m10, m11;
635 
636  m00 = slerp(m1, m2, t);
637  m01 = slerp(m2, m3, t);
638  m02 = slerp(m3, m4, t);
639 
640  m10 = slerp(m00, m01, t);
641  m11 = slerp(m01, m02, t);
642 
643  return slerp(m10, m11, t);
644 }
645 
648 
649 } // namespace math
650 } // namespace OPENVDB_VERSION_NAME
651 } // namespace openvdb
652 
653 #endif //OPENVDB_MATH_QUAT_H_HAS_BEEN_INCLUDED
654 
655 // ---------------------------------------------------------------------------
656 // Copyright (c) 2012-2015 DreamWorks Animation LLC
657 // All rights reserved. This software is distributed under the
658 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
3x3 matrix class.
Definition: Mat3.h:54
T det() const
Determinant of matrix.
Definition: Mat3.h:481
Quat operator*=(const Quat &q)
Assigns this to (this*q), e.g. q *= q1;.
Definition: Quat.h:417
static Quat zero()
Predefined constants, e.g. Quat q = Quat::identity();.
Definition: Quat.h:554
Quat inverse(T tolerance=T(0))
returns inverse of this
Definition: Quat.h:527
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Quat & add(const Quat &q1, const Quat &q2)
Definition: Quat.h:441
Quat operator/(T scalar) const
Return (this/scalar), e.g. q = q1 / scalar;.
Definition: Quat.h:430
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:407
Definition: Math.h:841
Quat & setZero()
Set "this" vector to zero.
Definition: Quat.h:312
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
std::string str() const
Definition: Quat.h:559
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Quat.h:251
Quat(const Quat &q)
Copy constructor.
Definition: Quat.h:213
T & y()
Definition: Vec3.h:98
bool isApproxEqual(const Type &a, const Type &b)
Return true if a is equal to b to within the default floating-point comparison tolerance.
Definition: Math.h:370
Vec3< T > eulerAngles(RotationOrder rotationOrder) const
Returns vector of x,y,z rotational components.
Definition: Quat.h:327
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:446
Vec3< typename MatType::value_type > eulerAngles(const MatType &mat, RotationOrder rotationOrder, typename MatType::value_type eps=static_cast< typename MatType::value_type >(1.0e-8))
Return the Euler angles composing the given rotation matrix.
Definition: Mat.h:314
Quat & scale(T scale, const Quat &q)
Definition: Quat.h:481
Mat3< T > bezLerp(const Mat3< T0 > &m1, const Mat3< T0 > &m2, const Mat3< T0 > &m3, const Mat3< T0 > &m4, T t)
Definition: Quat.h:630
T & z()
Definition: Quat.h:225
T & y()
Definition: Quat.h:224
T angle() const
Return angle of rotation.
Definition: Quat.h:254
Quat< float > Quats
Definition: Quat.h:646
#define OPENVDB_VERSION_NAME
Definition: version.h:43
void write(std::ostream &os) const
Definition: Quat.h:585
Quat derivative(const Vec3< T > &omega) const
Definition: Quat.h:499
Quat< double > Quatd
Definition: Quat.h:647
Quat operator+(const Quat &q) const
Return (this+q), e.g. q = q1 + q2;.
Definition: Quat.h:391
Vec3< T0 > transform(const Vec3< T0 > &v) const
Definition: Mat3.h:508
Quat & operator=(const Quat &q)
Assignment operator.
Definition: Quat.h:331
T w() const
Definition: Quat.h:232
T y() const
Definition: Quat.h:230
Quat(math::Axis axis, T angle)
Constructor given rotation as axis and angle.
Definition: Quat.h:147
Quat & operator+=(const Quat &q)
Add quaternion q to "this" quaternion, e.g. q += q1;.
Definition: Quat.h:358
T dot(const Quat &q) const
Dot product.
Definition: Quat.h:492
Definition: Mat.h:146
RotationOrder
Definition: Math.h:845
T & operator[](int i)
Array style reference to the components, e.g. q[3] = 1.34f;.
Definition: Quat.h:238
Quat< T > operator*(S scalar, const Quat< T > &q)
Returns V, where for .
Definition: Quat.h:598
Definition: Exceptions.h:39
Quat & operator*=(T scalar)
Scale "this" quaternion by scalar, e.g. q *= scalar;.
Definition: Quat.h:380
Quat operator*(const Quat &q) const
Return (this*q), e.g. q = q1 * q2;.
Definition: Quat.h:403
void read(std::istream &is)
Definition: Quat.h:588
T x() const
Get the component, e.g. float f = q.w();.
Definition: Quat.h:229
Definition: Math.h:840
static unsigned numElements()
Definition: Quat.h:235
T & z()
Definition: Vec3.h:99
Axis
Definition: Math.h:838
Quat & mult(const Quat &q1, const Quat &q2)
Definition: Quat.h:465
Quat(const Mat3< T1 > &rot)
Constructor given a rotation matrix.
Definition: Quat.h:160
Quat & setAxisAngle(const Vec3< T > &axis, T angle)
Definition: Quat.h:297
Quat & setIdentity()
Set "this" vector to identity.
Definition: Quat.h:319
friend std::ostream & operator<<(std::ostream &stream, const Quat &q)
Output to the stream, e.g. std::cout << q << std::endl;.
Definition: Quat.h:576
Quat & operator-=(const Quat &q)
Subtract quaternion q from "this" quaternion, e.g. q -= q1;.
Definition: Quat.h:369
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Quat.h:248
static Quat identity()
Definition: Quat.h:555
Definition: Mat.h:145
Vec3< T > axis() const
Return axis of rotation.
Definition: Quat.h:269
Mat3< T > slerp(const Mat3< T0 > &m1, const Mat3< T0 > &m2, T t)
Interpolate between m1 and m2. Converts to quaternion form and uses slerp m1 and m2 must be rotation ...
Definition: Quat.h:605
Quat(T x, T y, T z, T w)
Constructor with four arguments, e.g. Quatf q(1,2,3,4);.
Definition: Quat.h:111
Quat operator-() const
Negation operator, e.g. q = -q;.
Definition: Quat.h:436
bool eq(const Quat &q, T eps=1.0e-7) const
Test if "this" is equivalent to q with tolerance of eps value.
Definition: Quat.h:351
Quat conjugate() const
Definition: Quat.h:541
Definition: Exceptions.h:78
Quat(T *a)
Constructor with array argument, e.g. float a[4]; Quatf q(a);.
Definition: Quat.h:121
Quat operator-(const Quat &q) const
Return (this-q), e.g. q = q1 - q2;.
Definition: Quat.h:397
bool normalize(T eps=T(1.0e-8))
this = normalized this
Definition: Quat.h:508
Quat(const Vec3< T > &axis, T angle)
Definition: Quat.h:132
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
T & x()
Reference to the component, e.g. q.x() = 4.5f;.
Definition: Quat.h:223
Quat unit() const
this = normalized this
Definition: Quat.h:517
bool operator==(const Quat &q) const
Equality operator, does exact floating point comparisons.
Definition: Quat.h:342
Vec3< T > rotateVector(const Vec3< T > &v) const
Return rotated vector by "this" quaternion.
Definition: Quat.h:547
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition: Mat.h:594
T z() const
Definition: Quat.h:231
Definition: Math.h:839
Quat operator*(T scalar) const
Return (this*scalar), e.g. q = q1 * scalar;.
Definition: Quat.h:424
bool isUnitary(const MatType &m)
Determine if a matrix is unitary (i.e., rotation or reflection).
Definition: Mat.h:863
T trace() const
Trace of matrix.
Definition: Mat3.h:491
Quat & sub(const Quat &q1, const Quat &q2)
Definition: Quat.h:453
T & w()
Definition: Quat.h:226
T operator[](int i) const
Array style constant reference to the components, e.g. float f = q[1];.
Definition: Quat.h:241
Quat & init()
"this" quaternion gets initialized to identity, same as setIdentity()
Definition: Quat.h:293
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:97
Quat & init(T x, T y, T z, T w)
"this" quaternion gets initialized to [x, y, z, w]
Definition: Quat.h:286
Quat()
Trivial constructor, the quaternion is NOT initialized.
Definition: Quat.h:108