OpenVDB 5.1.0

Quat.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2018 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 "Mat.h"
35 #include "Mat3.h"
36 #include "Math.h"
37 #include "Vec3.h"
38 #include <openvdb/Exceptions.h>
39 #include <cmath>
40 #include <iostream>
41 #include <sstream>
42 #include <string>
43
44
45 namespace openvdb {
46 OPENVDB_USE_VERSION_NAMESPACE
47 namespace OPENVDB_VERSION_NAME {
48 namespace math {
49
50 template<typename T> class Quat;
51
53 template <typename T>
54 Quat<T> slerp(const Quat<T> &q1, const Quat<T> &q2, T t, T tolerance=0.00001)
55 {
56 T qdot, angle, sineAngle;
57
58 qdot = q1.dot(q2);
59
60 if (fabs(qdot) >= 1.0) {
61 angle = 0; // not necessary but suppresses compiler warning
62 sineAngle = 0;
63 } else {
64 angle = acos(qdot);
65 sineAngle = sin(angle);
66 }
67
68 //
69 // Denominator close to 0 corresponds to the case where the
70 // two quaternions are close to the same rotation. In this
71 // case linear interpolation is used but we normalize to
72 // guarantee unit length
73 //
74 if (sineAngle <= tolerance) {
75 T s = 1.0 - t;
76
77 Quat<T> qtemp(s * q1[0] + t * q2[0], s * q1[1] + t * q2[1],
78 s * q1[2] + t * q2[2], s * q1[3] + t * q2[3]);
79 //
80 // Check the case where two close to antipodal quaternions were
81 // blended resulting in a nearly zero result which can happen,
82 // for example, if t is close to 0.5. In this case it is not safe
83 // to project back onto the sphere.
84 //
85 double lengthSquared = qtemp.dot(qtemp);
86
87 if (lengthSquared <= tolerance * tolerance) {
88 qtemp = (t < 0.5) ? q1 : q2;
89 } else {
90 qtemp *= 1.0 / sqrt(lengthSquared);
91 }
92 return qtemp;
93 } else {
94
95 T sine = 1.0 / sineAngle;
96 T a = sin((1.0 - t) * angle) * sine;
97 T b = sin(t * angle) * sine;
98 return Quat<T>(a * q1[0] + b * q2[0], a * q1[1] + b * q2[1],
99 a * q1[2] + b * q2[2], a * q1[3] + b * q2[3]);
100 }
101
102 }
103
104 template<typename T>
105 class Quat
106 {
107 public:
109 Quat() {}
110
112 Quat(T x, T y, T z, T w)
113 {
114 mm[0] = x;
115 mm[1] = y;
116 mm[2] = z;
117 mm[3] = w;
118
119 }
120
122 Quat(T *a)
123 {
124 mm[0] = a[0];
125 mm[1] = a[1];
126 mm[2] = a[2];
127 mm[3] = a[3];
128
129 }
130
133 Quat(const Vec3<T> &axis, T angle)
134 {
135 // assert( REL_EQ(axis.length(), 1.) );
136
137 T s = T(sin(angle*T(0.5)));
138
139 mm[0] = axis.x() * s;
140 mm[1] = axis.y() * s;
141 mm[2] = axis.z() * s;
142
143 mm[3] = T(cos(angle*T(0.5)));
144
145 }
146
148 Quat(math::Axis axis, T angle)
149 {
150 T s = T(sin(angle*T(0.5)));
151
152 mm[0] = (axis==math::X_AXIS) * s;
153 mm[1] = (axis==math::Y_AXIS) * s;
154 mm[2] = (axis==math::Z_AXIS) * s;
155
156 mm[3] = T(cos(angle*T(0.5)));
157 }
158
160 template<typename T1>
161 Quat(const Mat3<T1> &rot) {
162
163 // verify that the matrix is really a rotation
164 if(!isUnitary(rot)) { // unitary is reflection or rotation
165 OPENVDB_THROW(ArithmeticError,
166 "A non-rotation matrix can not be used to construct a quaternion");
167 }
168 if (!isApproxEqual(rot.det(), T1(1))) { // rule out reflection
169 OPENVDB_THROW(ArithmeticError,
170 "A reflection matrix can not be used to construct a quaternion");
171 }
172
173 T trace(rot.trace());
174 if (trace > 0) {
175
176 T q_w = 0.5 * std::sqrt(trace+1);
177 T factor = 0.25 / q_w;
178
179 mm[0] = factor * (rot(1,2) - rot(2,1));
180 mm[1] = factor * (rot(2,0) - rot(0,2));
181 mm[2] = factor * (rot(0,1) - rot(1,0));
182 mm[3] = q_w;
183 } else if (rot(0,0) > rot(1,1) && rot(0,0) > rot(2,2)) {
184
185 T q_x = 0.5 * sqrt(rot(0,0)- rot(1,1)-rot(2,2)+1);
186 T factor = 0.25 / q_x;
187
188 mm[0] = q_x;
189 mm[1] = factor * (rot(0,1) + rot(1,0));
190 mm[2] = factor * (rot(2,0) + rot(0,2));
191 mm[3] = factor * (rot(1,2) - rot(2,1));
192 } else if (rot(1,1) > rot(2,2)) {
193
194 T q_y = 0.5 * sqrt(rot(1,1)-rot(0,0)-rot(2,2)+1);
195 T factor = 0.25 / q_y;
196
197 mm[0] = factor * (rot(0,1) + rot(1,0));
198 mm[1] = q_y;
199 mm[2] = factor * (rot(1,2) + rot(2,1));
200 mm[3] = factor * (rot(2,0) - rot(0,2));
201 } else {
202
203 T q_z = 0.5 * sqrt(rot(2,2)-rot(0,0)-rot(1,1)+1);
204 T factor = 0.25 / q_z;
205
206 mm[0] = factor * (rot(2,0) + rot(0,2));
207 mm[1] = factor * (rot(1,2) + rot(2,1));
208 mm[2] = q_z;
209 mm[3] = factor * (rot(0,1) - rot(1,0));
210 }
211 }
212
214 Quat(const Quat &q)
215 {
216 mm[0] = q.mm[0];
217 mm[1] = q.mm[1];
218 mm[2] = q.mm[2];
219 mm[3] = q.mm[3];
220
221 }
222
224 T& x() { return mm[0]; }
225 T& y() { return mm[1]; }
226 T& z() { return mm[2]; }
227 T& w() { return mm[3]; }
228
230 T x() const { return mm[0]; }
231 T y() const { return mm[1]; }
232 T z() const { return mm[2]; }
233 T w() const { return mm[3]; }
234
235 // Number of elements
236 static unsigned numElements() { return 4; }
237
239 T& operator[](int i) { return mm[i]; }
240
242 T operator[](int i) const { return mm[i]; }
243
245 operator T*() { return mm; }
246 operator const T*() const { return mm; }
247
249 T& operator()(int i) { return mm[i]; }
250
252 T operator()(int i) const { return mm[i]; }
253
255 T angle() const
256 {
257 T sqrLength = mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2];
258
259 if ( sqrLength > 1.0e-8 ) {
260
261 return T(T(2.0) * acos(mm[3]));
262
263 } else {
264
265 return T(0.0);
266 }
267 }
268
270 Vec3<T> axis() const
271 {
272 T sqrLength = mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2];
273
274 if ( sqrLength > 1.0e-8 ) {
275
276 T invLength = T(T(1)/sqrt(sqrLength));
277
278 return Vec3<T>( mm[0]*invLength, mm[1]*invLength, mm[2]*invLength );
279 } else {
280
281 return Vec3<T>(1,0,0);
282 }
283 }
284
285
287 Quat& init(T x, T y, T z, T w)
288 {
289 mm[0] = x; mm[1] = y; mm[2] = z; mm[3] = w;
290 return *this;
291 }
292
294 Quat& init() { return setIdentity(); }
295
298 Quat& setAxisAngle(const Vec3<T>& axis, T angle)
299 {
300
301 T s = T(sin(angle*T(0.5)));
302
303 mm[0] = axis.x() * s;
304 mm[1] = axis.y() * s;
305 mm[2] = axis.z() * s;
306
307 mm[3] = T(cos(angle*T(0.5)));
308
309 return *this;
310 } // axisAngleTest
311
313 Quat& setZero()
314 {
315 mm[0] = mm[1] = mm[2] = mm[3] = 0;
316 return *this;
317 }
318
320 Quat& setIdentity()
321 {
322 mm[0] = mm[1] = mm[2] = 0;
323 mm[3] = 1;
324 return *this;
325 }
326
328 Vec3<T> eulerAngles(RotationOrder rotationOrder) const
329 { return math::eulerAngles(Mat3<T>(*this), rotationOrder); }
330
332 Quat& operator=(const Quat &q)
333 {
334 mm[0] = q.mm[0];
335 mm[1] = q.mm[1];
336 mm[2] = q.mm[2];
337 mm[3] = q.mm[3];
338
339 return *this;
340 }
341
343 bool operator==(const Quat &q) const
344 {
345 return (isExactlyEqual(mm[0],q.mm[0]) &&
346 isExactlyEqual(mm[1],q.mm[1]) &&
347 isExactlyEqual(mm[2],q.mm[2]) &&
348 isExactlyEqual(mm[3],q.mm[3]) );
349 }
350
352 bool eq(const Quat &q, T eps=1.0e-7) const
353 {
354 return isApproxEqual(mm[0],q.mm[0],eps) && isApproxEqual(mm[1],q.mm[1],eps) &&
355 isApproxEqual(mm[2],q.mm[2],eps) && isApproxEqual(mm[3],q.mm[3],eps) ;
356 } // trivial
357
359 Quat& operator+=(const Quat &q)
360 {
361 mm[0] += q.mm[0];
362 mm[1] += q.mm[1];
363 mm[2] += q.mm[2];
364 mm[3] += q.mm[3];
365
366 return *this;
367 }
368
370 Quat& operator-=(const Quat &q)
371 {
372 mm[0] -= q.mm[0];
373 mm[1] -= q.mm[1];
374 mm[2] -= q.mm[2];
375 mm[3] -= q.mm[3];
376
377 return *this;
378 }
379
381 Quat& operator*=(T scalar)
382 {
383 mm[0] *= scalar;
384 mm[1] *= scalar;
385 mm[2] *= scalar;
386 mm[3] *= scalar;
387
388 return *this;
389 }
390
392 Quat operator+(const Quat &q) const
393 {
394 return Quat<T>(mm[0]+q.mm[0], mm[1]+q.mm[1], mm[2]+q.mm[2], mm[3]+q.mm[3]);
395 }
396
398 Quat operator-(const Quat &q) const
399 {
400 return Quat<T>(mm[0]-q.mm[0], mm[1]-q.mm[1], mm[2]-q.mm[2], mm[3]-q.mm[3]);
401 }
402
404 Quat operator*(const Quat &q) const
405 {
406 Quat<T> prod;
407
408 prod.mm[0] = mm[3]*q.mm[0] + mm[0]*q.mm[3] + mm[1]*q.mm[2] - mm[2]*q.mm[1];
409 prod.mm[1] = mm[3]*q.mm[1] + mm[1]*q.mm[3] + mm[2]*q.mm[0] - mm[0]*q.mm[2];
410 prod.mm[2] = mm[3]*q.mm[2] + mm[2]*q.mm[3] + mm[0]*q.mm[1] - mm[1]*q.mm[0];
411 prod.mm[3] = mm[3]*q.mm[3] - mm[0]*q.mm[0] - mm[1]*q.mm[1] - mm[2]*q.mm[2];
412
413 return prod;
414
415 }
416
418 Quat operator*=(const Quat &q)
419 {
420 *this = *this * q;
421 return *this;
422 }
423
425 Quat operator*(T scalar) const
426 {
427 return Quat<T>(mm[0]*scalar, mm[1]*scalar, mm[2]*scalar, mm[3]*scalar);
428 }
429
431 Quat operator/(T scalar) const
432 {
433 return Quat<T>(mm[0]/scalar, mm[1]/scalar, mm[2]/scalar, mm[3]/scalar);
434 }
435
437 Quat operator-() const
438 { return Quat<T>(-mm[0], -mm[1], -mm[2], -mm[3]); }
439
442 Quat& add(const Quat &q1, const Quat &q2)
443 {
444 mm[0] = q1.mm[0] + q2.mm[0];
445 mm[1] = q1.mm[1] + q2.mm[1];
446 mm[2] = q1.mm[2] + q2.mm[2];
447 mm[3] = q1.mm[3] + q2.mm[3];
448
449 return *this;
450 }
451
454 Quat& sub(const Quat &q1, const Quat &q2)
455 {
456 mm[0] = q1.mm[0] - q2.mm[0];
457 mm[1] = q1.mm[1] - q2.mm[1];
458 mm[2] = q1.mm[2] - q2.mm[2];
459 mm[3] = q1.mm[3] - q2.mm[3];
460
461 return *this;
462 }
463
466 Quat& mult(const Quat &q1, const Quat &q2)
467 {
468 mm[0] = q1.mm[3]*q2.mm[0] + q1.mm[0]*q2.mm[3] +
469 q1.mm[1]*q2.mm[2] - q1.mm[2]*q2.mm[1];
470 mm[1] = q1.mm[3]*q2.mm[1] + q1.mm[1]*q2.mm[3] +
471 q1.mm[2]*q2.mm[0] - q1.mm[0]*q2.mm[2];
472 mm[2] = q1.mm[3]*q2.mm[2] + q1.mm[2]*q2.mm[3] +
473 q1.mm[0]*q2.mm[1] - q1.mm[1]*q2.mm[0];
474 mm[3] = q1.mm[3]*q2.mm[3] - q1.mm[0]*q2.mm[0] -
475 q1.mm[1]*q2.mm[1] - q1.mm[2]*q2.mm[2];
476
477 return *this;
478 }
479
482 Quat& scale(T scale, const Quat &q)
483 {
484 mm[0] = scale * q.mm[0];
485 mm[1] = scale * q.mm[1];
486 mm[2] = scale * q.mm[2];
487 mm[3] = scale * q.mm[3];
488
489 return *this;
490 }
491
493 T dot(const Quat &q) const
494 {
495 return (mm[0]*q.mm[0] + mm[1]*q.mm[1] + mm[2]*q.mm[2] + mm[3]*q.mm[3]);
496 }
497
500 Quat derivative(const Vec3<T>& omega) const
501 {
502 return Quat<T>( +w()*omega.x() -z()*omega.y() +y()*omega.z() ,
503 +z()*omega.x() +w()*omega.y() -x()*omega.z() ,
504 -y()*omega.x() +x()*omega.y() +w()*omega.z() ,
505 -x()*omega.x() -y()*omega.y() -z()*omega.z() );
506 }
507
509 bool normalize(T eps = T(1.0e-8))
510 {
511 T d = T(sqrt(mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2] + mm[3]*mm[3]));
512 if( isApproxEqual(d, T(0.0), eps) ) return false;
513 *this *= ( T(1)/d );
514 return true;
515 }
516
518 Quat unit() const
519 {
520 T d = sqrt(mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2] + mm[3]*mm[3]);
521 if( isExactlyEqual(d , T(0.0) ) )
522 OPENVDB_THROW(ArithmeticError,
523 "Normalizing degenerate quaternion");
524 return *this / d;
525 }
526
528 Quat inverse(T tolerance = T(0))
529 {
530 T d = mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2] + mm[3]*mm[3];
531 if( isApproxEqual(d, T(0.0), tolerance) )
532 OPENVDB_THROW(ArithmeticError,
533 "Cannot invert degenerate quaternion");
534 Quat result = *this/-d;
535 result.mm[3] = -result.mm[3];
536 return result;
537 }
538
539
542 Quat conjugate() const
543 {
544 return Quat<T>(-mm[0], -mm[1], -mm[2], mm[3]);
545 }
546
548 Vec3<T> rotateVector(const Vec3<T> &v) const
549 {
550 Mat3<T> m(*this);
551 return m.transform(v);
552 }
553
555 static Quat zero() { return Quat<T>(0,0,0,0); }
556 static Quat identity() { return Quat<T>(0,0,0,1); }
557
559 std::string str() const
560 {
561 std::ostringstream buffer;
562
563 buffer << "[";
564
565 // For each column
566 for (unsigned j(0); j < 4; j++) {
567 if (j) buffer << ", ";
568 buffer << mm[j];
569 }
570
571 buffer << "]";
572
573 return buffer.str();
574 }
575
577 friend std::ostream& operator<<(std::ostream &stream, const Quat &q)
578 {
579 stream << q.str();
580 return stream;
581 }
582
583 friend Quat slerp<>(const Quat &q1, const Quat &q2, T t, T tolerance);
584
585 void write(std::ostream& os) const { os.write(static_cast<char*>(&mm), sizeof(T) * 4); }
586 void read(std::istream& is) { is.read(static_cast<char*>(&mm), sizeof(T) * 4); }
587
588 protected:
589 T mm[4];
590 };
591
593 template <typename S, typename T>
594 Quat<T> operator*(S scalar, const Quat<T> &q) { return q*scalar; }
595
596
600 template <typename T, typename T0>
601 Mat3<T> slerp(const Mat3<T0> &m1, const Mat3<T0> &m2, T t)
602 {
603 using MatType = Mat3<T>;
604
605 Quat<T> q1(m1);
606 Quat<T> q2(m2);
607
608 if (q1.dot(q2) < 0) q2 *= -1;
609
610 Quat<T> qslerp = slerp<T>(q1, q2, static_cast<T>(t));
611 MatType m = rotation<MatType>(qslerp);
612 return m;
613 }
614
615
616
625 template <typename T, typename T0>
626 Mat3<T> bezLerp(const Mat3<T0> &m1, const Mat3<T0> &m2,
627 const Mat3<T0> &m3, const Mat3<T0> &m4,
628 T t)
629 {
630 Mat3<T> m00, m01, m02, m10, m11;
631
632 m00 = slerp(m1, m2, t);
633 m01 = slerp(m2, m3, t);
634 m02 = slerp(m3, m4, t);
635
636 m10 = slerp(m00, m01, t);
637 m11 = slerp(m01, m02, t);
638
639 return slerp(m10, m11, t);
640 }
641
642 using Quats = Quat<float>;
643 using Quatd = Quat<double>;
644
645 } // namespace math
646
647
648 template<> inline math::Quats zeroVal<math::Quats >() { return math::Quats::zero(); }
649 template<> inline math::Quatd zeroVal<math::Quatd >() { return math::Quatd::zero(); }
650
651 } // namespace OPENVDB_VERSION_NAME
652 } // namespace openvdb
653
654 #endif //OPENVDB_MATH_QUAT_H_HAS_BEEN_INCLUDED
655
656 // Copyright (c) 2012-2018 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/ )
openvdb::v5_1::math::isExactlyEqual
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:395
openvdb::v5_1::math::Quat::init
Quat & init()
"this" quaternion gets initialized to identity, same as setIdentity()
Definition: Quat.h:294
openvdb::v5_1::math::Quat::init
Quat & init(T x, T y, T z, T w)
"this" quaternion gets initialized to [x, y, z, w]
Definition: Quat.h:287
openvdb::v5_1::math::slerp
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:601
openvdb::v5_1::math::Quat::operator+=
Quat & operator+=(const Quat &q)
Add quaternion q to "this" quaternion, e.g. q += q1;.
Definition: Quat.h:359
Vec3.h
openvdb::v5_1::math::Quat::operator==
bool operator==(const Quat &q) const
Equality operator, does exact floating point comparisons.
Definition: Quat.h:343
openvdb::v5_1::math::Quat::mult
Quat & mult(const Quat &q1, const Quat &q2)
Definition: Quat.h:466
openvdb::v5_1::math::Quat::read
void read(std::istream &is)
Definition: Quat.h:586
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
openvdb::v5_1::math::Quat::numElements
static unsigned numElements()
Definition: Quat.h:236
openvdb::v5_1::math::Axis
Axis
Definition: Math.h:856
openvdb::v5_1::math::Quat::operator<<
friend std::ostream & operator<<(std::ostream &stream, const Quat &q)
Output to the stream, e.g. std::cout << q << std::endl;.
Definition: Quat.h:577
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
openvdb::v5_1::math::Quat::setAxisAngle
Quat & setAxisAngle(const Vec3< T > &axis, T angle)
Definition: Quat.h:298
openvdb::v5_1::math::Quat::Quat
Quat(const Quat &q)
Copy constructor.
Definition: Quat.h:214
openvdb::v5_1::math::Quat::operator*=
Quat & operator*=(T scalar)
Scale "this" quaternion by scalar, e.g. q *= scalar;.
Definition: Quat.h:381
openvdb::v5_1::math::Quat::Quat
Quat(const Mat3< T1 > &rot)
Constructor given a rotation matrix.
Definition: Quat.h:161
openvdb::v5_1::math::Quat::eq
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:352
openvdb::v5_1::math::Quat::setIdentity
Quat & setIdentity()
Set "this" vector to identity.
Definition: Quat.h:320
openvdb::v5_1::math::Quat::w
T & w()
Definition: Quat.h:227
openvdb::v5_1::math::Quat::angle
T angle() const
Return angle of rotation.
Definition: Quat.h:255
openvdb::v5_1::math::Quat::zero
static Quat zero()
Predefined constants, e.g. Quat q = Quat::identity();.
Definition: Quat.h:555
openvdb::v5_1::math::Mat3::trace
T trace() const
Trace of matrix.
Definition: Mat3.h:536
openvdb::v5_1::math::Vec3
Definition: Mat.h:197
openvdb::v5_1::math::Quat::operator*
Quat operator*(T scalar) const
Return (this*scalar), e.g. q = q1 * scalar;.
Definition: Quat.h:425
openvdb::v5_1::math::Quat::x
T & x()
Reference to the component, e.g. q.x() = 4.5f;.
Definition: Quat.h:224
openvdb::v5_1::math::Quat::dot
T dot(const Quat &q) const
Dot product.
Definition: Quat.h:493
openvdb::v5_1::math::scale
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition: Mat.h:645
openvdb::v5_1::math::angle
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:472
openvdb::v5_1::math::Quat::operator+
Quat operator+(const Quat &q) const
Return (this+q), e.g. q = q1 + q2;.
Definition: Quat.h:392
Mat3.h
openvdb::v5_1::math::Quat::write
void write(std::ostream &os) const
Definition: Quat.h:585
openvdb::v5_1::math::Quat::mm
T mm[4]
Definition: Quat.h:589
openvdb::v5_1::math::Quat::identity
static Quat identity()
Definition: Quat.h:556
openvdb::v5_1::math::Mat3
3x3 matrix class.
Definition: Mat3.h:55
openvdb::v5_1::math::Quat::setZero
Quat & setZero()
Set "this" vector to zero.
Definition: Quat.h:313
openvdb::v5_1::math::Quat::Quat
Quat(math::Axis axis, T angle)
Constructor given rotation as axis and angle.
Definition: Quat.h:148
openvdb::v5_1::math::Quat::unit
Quat unit() const
this = normalized this
Definition: Quat.h:518
openvdb::v5_1::math::Quat::operator[]
T & operator[](int i)
Array style reference to the components, e.g. q[3] = 1.34f;.
Definition: Quat.h:239
Exceptions.h
openvdb::v5_1::math::Quat::operator-
Quat operator-() const
Negation operator, e.g. q = -q;.
Definition: Quat.h:437
openvdb::v5_1::math::Quat
Definition: Mat.h:196
openvdb::v5_1::math::Mat3::det
T det() const
Determinant of matrix.
Definition: Mat3.h:527
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
openvdb::v5_1::math::RotationOrder
RotationOrder
Definition: Math.h:863
openvdb::v5_1::math::Quat::rotateVector
Vec3< T > rotateVector(const Vec3< T > &v) const
Return rotated vector by "this" quaternion.
Definition: Quat.h:548
openvdb::v5_1::ArithmeticError
Definition: Exceptions.h:83
openvdb::v5_1::math::Vec3::x
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:110
openvdb::v5_1::math::Quat::Quat
Quat(T *a)
Constructor with array argument, e.g. float a[4]; Quatf q(a);.
Definition: Quat.h:122
openvdb
Definition: Exceptions.h:40
openvdb::v5_1::math::Z_AXIS
Definition: Math.h:859
openvdb::v5_1::math::Quat::operator()
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Quat.h:249
openvdb::v5_1::math::Quat::operator[]
T operator[](int i) const
Array style constant reference to the components, e.g. float f = q[1];.
Definition: Quat.h:242
openvdb::v5_1::math::Y_AXIS
Definition: Math.h:858
openvdb::v5_1::math::operator*
Quat< T > operator*(S scalar, const Quat< T > &q)
Multiply each element of the given quaternion by scalar and return the result.
Definition: Quat.h:594
openvdb::v5_1::math::Quat::str
std::string str() const
Definition: Quat.h:559
openvdb::v5_1::math::Quat::operator-
Quat operator-(const Quat &q) const
Return (this-q), e.g. q = q1 - q2;.
Definition: Quat.h:398
openvdb::v5_1::math::Quat::operator*
Quat operator*(const Quat &q) const
Return (this*q), e.g. q = q1 * q2;.
Definition: Quat.h:404
openvdb::v5_1::math::Quat::axis
Vec3< T > axis() const
Return axis of rotation.
Definition: Quat.h:270
openvdb::v5_1::math::Quat::Quat
Quat(T x, T y, T z, T w)
Constructor with four arguments, e.g. Quatf q(1,2,3,4);.
Definition: Quat.h:112
openvdb::v5_1::math::Quat::y
T y() const
Definition: Quat.h:231
openvdb::v5_1::math::Mat3::transform
Vec3< T0 > transform(const Vec3< T0 > &v) const
Definition: Mat3.h:553
openvdb::v5_1::math::eulerAngles
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:365
openvdb::v5_1::math::Quat::z
T z() const
Definition: Quat.h:232
openvdb::v5_1::math::Quat::operator*=
Quat operator*=(const Quat &q)
Assigns this to (this*q), e.g. q *= q1;.
Definition: Quat.h:418
openvdb::v5_1::math::isApproxEqual
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:358
openvdb::v5_1::math::Quat::derivative
Quat derivative(const Vec3< T > &omega) const
Definition: Quat.h:500
openvdb::v5_1::math::bezLerp
Mat3< T > bezLerp(const Mat3< T0 > &m1, const Mat3< T0 > &m2, const Mat3< T0 > &m3, const Mat3< T0 > &m4, T t)
Definition: Quat.h:626
openvdb::v5_1::math::Quat::x
T x() const
Get the component, e.g. float f = q.w();.
Definition: Quat.h:230
openvdb::v5_1::math::X_AXIS
Definition: Math.h:857
openvdb::v5_1::math::Quat::operator/
Quat operator/(T scalar) const
Return (this/scalar), e.g. q = q1 / scalar;.
Definition: Quat.h:431
openvdb::v5_1::math::Quat::sub
Quat & sub(const Quat &q1, const Quat &q2)
Definition: Quat.h:454
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
openvdb::v5_1::math::Quat::add
Quat & add(const Quat &q1, const Quat &q2)
Definition: Quat.h:442
openvdb::v5_1::math::Quat::operator()
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Quat.h:252
openvdb::v5_1::math::Quat::inverse
Quat inverse(T tolerance=T(0))
returns inverse of this
Definition: Quat.h:528
openvdb::v5_1::math::Quat::w
T w() const
Definition: Quat.h:233
openvdb::v5_1::math::Quat::z
T & z()
Definition: Quat.h:226
openvdb::v5_1::math::Quat::y
T & y()
Definition: Quat.h:225
openvdb::v5_1::math::isUnitary
bool isUnitary(const MatType &m)
Determine if a matrix is unitary (i.e., rotation or reflection).
Definition: Mat.h:919
Mat.h
openvdb::v5_1::math::Quat::eulerAngles
Vec3< T > eulerAngles(RotationOrder rotationOrder) const
Returns vector of x,y,z rotational components.
Definition: Quat.h:328
openvdb::v5_1::math::Quat::operator-=
Quat & operator-=(const Quat &q)
Subtract quaternion q from "this" quaternion, e.g. q -= q1;.
Definition: Quat.h:370
openvdb::v5_1::math::Quat::conjugate
Quat conjugate() const
Definition: Quat.h:542
openvdb::v5_1::math::Quat::Quat
Quat()
Trivial constructor, the quaternion is NOT initialized.
Definition: Quat.h:109
openvdb::v5_1::math::Quat::Quat
Quat(const Vec3< T > &axis, T angle)
Definition: Quat.h:133
openvdb::v5_1::math::Quat::scale
Quat & scale(T scale, const Quat &q)
Definition: Quat.h:482
openvdb::v5_1::math::Vec3::z
T & z()
Definition: Vec3.h:112
openvdb::v5_1::math::Quat::operator=
Quat & operator=(const Quat &q)
Assignment operator.
Definition: Quat.h:332
openvdb::v5_1::math::Quat::normalize
bool normalize(T eps=T(1.0e-8))
this = normalized this
Definition: Quat.h:509
openvdb::v5_1::math::Vec3::y
T & y()
Definition: Vec3.h:111