Ocean
Loading...
Searching...
No Matches
Rotation.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_MATH_ROTATION_H
9#define META_OCEAN_MATH_ROTATION_H
10
11#include "ocean/math/Math.h"
12#include "ocean/math/Euler.h"
13#include "ocean/math/Numeric.h"
16
18
19#include <vector>
20
21namespace Ocean
22{
23
24// Forward declaration.
25template <typename T> class SquareMatrixT3;
26
27// Forward declaration.
28template <typename T> class HomogenousMatrixT4;
29
30// Forward declaration.
31template <typename T> class RotationT;
32
33/**
34 * Definition of the Rotation object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag either with single or double precision float data type.
35 * @see RotationT
36 * @ingroup math
37 */
39
40/**
41 * Instantiation of the RotationT template class using a double precision float data type.
42 * @see RotationT
43 * @ingroup math
44 */
46
47/**
48 * Instantiation of the RotationT template class using a single precision float data type.
49 * @see RotationT
50 * @ingroup math
51 */
53
54/**
55 * Definition of a typename alias for vectors with RotationT objects.
56 * @see RotationT
57 * @ingroup math
58 */
59template <typename T>
60using RotationsT = std::vector<RotationT<T>>;
61
62/**
63 * Definition of a vector holding rotation objects.
64 * @see Rotation
65 * @ingroup math
66 */
67typedef std::vector<Rotation> Rotations;
68
69/**
70 * This class implements a axis-angle rotation using floating point values.
71 * The angle is defined in radian [0, 2*PI).<br>
72 * The four elements are stored with order: (x, y, z, angle).
73 * @tparam T Data type used to represent axis and angle
74 * @see Rotation, RotationF, RotationD, Quaternion, Euler, SquareMatrix3, ExponentialMap.
75 * @ingroup math
76 */
77template <typename T>
79{
80 public:
81
82 /**
83 * Definition of the used data type.
84 */
85 typedef T Type;
86
87 public:
88
89 /**
90 * Creates a rotation object with default values so that the rotation represents the identity rotation.
91 * The axis will be set to (0, 1, 0) and the angle to 0.
92 */
93 RotationT() = default;
94
95 /**
96 * Creates a rotation object by four given values.
97 * The axis must have length 1.
98 * @param x X value of the rotation axis
99 * @param y Y value of the rotation axis
100 * @param z Z value of the rotation axis
101 * @param angle The angle of the rotation in radian, with range (-infinity, infinity), however will be converted to the range [0.0, 2 * PI)
102 */
103 RotationT(const T x, const T y, const T z, const T angle);
104
105 /**
106 * Creates a rotation object by an axis and the angle.
107 * @param axis The axis of the rotation with length 1
108 * @param angle The angle of the rotation in radian, with range (-infinity, infinity), however will be converted to the range [0.0, 2 * PI)
109 */
110 RotationT(const VectorT3<T>& axis, const T angle);
111
112 /**
113 * Creates a rotation object based on two given unit vectors.
114 * The resulting rotation defines a transformation that rotates that reference vector into the offset vector: Rotation(reference, offset) = offset_R_reference.<br>
115 * The following equation holds:
116 * <pre>
117 * offset = Rotation(reference, offset) * reference.
118 * </pre>
119 * @param reference The reference vector, with length 1
120 * @param offset The offset vector, with length 1
121 */
122 RotationT(const VectorT3<T>& reference, const VectorT3<T>& offset);
123
124 /**
125 * Creates a rotation object by a given quaternion rotation.
126 * @param quaternion the quaternion rotation to create an axis-angle rotation from, must be valid
127 */
128 explicit RotationT(const QuaternionT<T>& quaternion);
129
130 /**
131 * Creates an angle-axis rotation by a given euler rotation.
132 * @param euler Euler rotation to create a angle-axis rotation from, must be valid
133 */
134 explicit RotationT(const EulerT<T>& euler);
135
136 /**
137 * Creates a rotation object by a given 3x3 rotation matrix.
138 * Beware: Ensure that the provided matrix does not contain any scale.
139 * @param matrix Rotation matrix to create a axis-angle rotation from, with determinant 1
140 */
141 explicit RotationT(const SquareMatrixT3<T>& matrix);
142
143 /**
144 * Creates a rotation object by a given 4x4 transformation matrix.
145 * @param transformation The transformation matrix to create a axis-angle rotation from, must be valid
146 */
147 explicit RotationT(const HomogenousMatrixT4<T>& transformation);
148
149 /**
150 * Creates a rotation object by an array with four elements.
151 * The element order in the array has to be: (x, y, z, angle).<br>
152 * The axis must have length 1, the angle is provided as radian with range (-infinity, infinity), however will be converted to the range [0.0, 2 * PI)
153 * @param valueArray Array with four elements
154 */
155 explicit RotationT(const T* valueArray);
156
157 /**
158 * Sets the axis of the rotation.
159 * @param axis The axis with length 1
160 */
161 void setAxis(const VectorT3<T>& axis);
162
163 /**
164 * Sets the angle of the rotation.
165 * @param angle The angle of rotation in radian, with range (-infinity, infinity), however will be converted to the range [0.0, 2 * PI)
166 */
167 void setAngle(const T angle);
168
169 /**
170 * Returns a pointer to the internal values.
171 * @return Pointer to the internal values
172 */
173 inline const T* data() const;
174
175 /**
176 * Returns a pointer to the internal values.
177 * @return Pointer to the internal values
178 */
179 inline T* data();
180
181 /**
182 * Returns the axis of the rotation.
183 * @return Rotation axis with unit length if the rotation is valid
184 */
185 inline VectorT3<T> axis() const;
186
187 /**
188 * Returns the angle of the rotation.
189 * @return Rotation angle in radian, with range [0.0, 2 * PI)
190 */
191 inline T angle() const;
192
193 /**
194 * Returns the inverted rotation, this rotation must be valid.
195 * @return Inverted rotation
196 * @see isValid(), invert().
197 */
198 RotationT inverted() const;
199
200 /**
201 * Inverts this rotation, this rotation must be valid.
202 * @see isValid(), inverted().
203 */
204 void invert();
205
206 /**
207 * Returns whether this rotation has valid parameters.
208 * @return True, if so
209 */
210 bool isValid() const;
211
212 /**
213 * Returns whether two rotations are identical up to a small epsilon.
214 * @param right The right operand
215 * @return True, if so
216 */
217 bool operator==(const RotationT<T>& right) const;
218
219 /**
220 * Returns whether two rotations are not identical up to a small epsilon.
221 * @param right The right operand
222 * @return True, if so
223 */
224 inline bool operator!=(const RotationT<T>& right) const;
225
226 /**
227 * Returns the inverse rotation, this rotation must be valid.
228 * @return Inverse rotation
229 */
230 RotationT operator-() const;
231
232 /**
233 * Multiplies two rotations, this rotation must be valid.
234 * @param quaternion The right rotation as unit quaternion, must be valid
235 * @return Resulting rotation
236 */
237 RotationT operator*(const QuaternionT<T>& quaternion) const;
238
239 /**
240 * Multiplies and assign two rotations, this rotation must be valid.
241 * @param quaternion The right rotation as unit quaternion, must be valid
242 * @return Reference to this rotation
243 */
244 RotationT& operator*=(const QuaternionT<T>& quaternion);
245
246 /**
247 * Multiplies two rotations, this rotation must be valid.
248 * @param right The right rotation to multiply, must be valid
249 * @return Resulting rotation
250 */
251 RotationT operator*(const RotationT<T>& right) const;
252
253 /**
254 * Multiplies and assign two rotations, this rotation must be valid.
255 * @param right The right rotation to multiply, must be valid
256 * @return Reference to this rotation
257 */
258 RotationT& operator*=(const RotationT<T>& right);
259
260 /**
261 * Rotates a 3D vector with this rotation, this rotation must be valid.
262 * @param vector The vector to rotate
263 * @return Rotated vector
264 */
265 VectorT3<T> operator*(const VectorT3<T>& vector) const;
266
267 /**
268 * Element access operator.
269 * @param index The index of the element to return, with range [0, 3]
270 * @return Internal element
271 */
272 inline T operator()(unsigned int index) const;
273
274 /**
275 * Element access operator.
276 * @param index The index of the element to return, with range [0, 3]
277 * @return Internal element
278 */
279 inline T& operator()(unsigned int index);
280
281 /**
282 * Element access operator.
283 * @param index The index of the element to return, with range [0, 3]
284 * @return Internal element
285 */
286 inline T operator[](unsigned int index) const;
287
288 /**
289 * Element access operator.
290 * @param index The index of the element to return, with range [0, 3]
291 * @return Internal element
292 */
293 inline T& operator[](unsigned int index);
294
295 /**
296 * Access operator.
297 * @return Pointer to the internal elements.
298 */
299 inline const T* operator()() const;
300
301 /**
302 * Access operator.
303 * @return Pointer to the internal elements.
304 */
305 inline T* operator()();
306
307 protected:
308
309 /// The four values of the angle-axis rotation.
310 T values_[4] = {T(0), T(1), T(0), T(0)};
311};
312
313template <typename T>
314RotationT<T>::RotationT(const T x, const T y, const T z, const T angle)
315{
316 values_[0] = x;
317 values_[1] = y;
318 values_[2] = z;
319
320 if (angle > NumericT<T>::pi2())
321 {
322 values_[3] = NumericT<T>::fmod(angle, NumericT<T>::pi2());
323 }
324 else if (angle < T(0.0))
325 {
326 ocean_assert(NumericT<T>::fmod(angle, NumericT<T>::pi2()) < T(0.0));
327 values_[3] = NumericT<T>::pi2() + NumericT<T>::fmod(angle, NumericT<T>::pi2());
328 }
329 else
330 {
331 values_[3] = angle;
332 }
333
334 ocean_assert(isValid());
335}
336
337template <typename T>
338RotationT<T>::RotationT(const VectorT3<T>& axis, const T angle)
339{
340 values_[0] = axis[0];
341 values_[1] = axis[1];
342 values_[2] = axis[2];
343
344 if (angle > NumericT<T>::pi2())
345 {
346 values_[3] = NumericT<T>::fmod(angle, NumericT<T>::pi2());
347 }
348 else if (angle < T(0.0))
349 {
350 ocean_assert(NumericT<T>::fmod(angle, NumericT<T>::pi2()) < T(0.0));
351 values_[3] = NumericT<T>::pi2() + NumericT<T>::fmod(angle, NumericT<T>::pi2());
352 }
353 else
354 {
355 values_[3] = angle;
356 }
357
358 ocean_assert(isValid());
359}
360
361template <typename T>
362RotationT<T>::RotationT(const VectorT3<T>& reference, const VectorT3<T>& offset)
363{
364 ocean_assert(NumericT<T>::isWeakEqual(reference.length(), 1));
365 ocean_assert(NumericT<T>::isWeakEqual(offset.length(), 1));
366
367 if (reference == offset)
368 {
369 values_[0] = 0;
370 values_[1] = 1;
371 values_[2] = 0;
372 values_[3] = 0;
373 }
374 else if (reference == -offset)
375 {
376 const VectorT3<T> perpendicular(reference.perpendicular().normalized());
377
378 values_[0] = perpendicular[0];
379 values_[1] = perpendicular[1];
380 values_[2] = perpendicular[2];
381 values_[3] = NumericT<T>::pi();
382 }
383 else
384 {
385 const VectorT3<T> axis(reference.cross(offset).normalized());
386
387 values_[0] = axis.x();
388 values_[1] = axis.y();
389 values_[2] = axis.z();
390 values_[3] = reference.angle(offset);
391 }
392
393 ocean_assert(isValid());
394 ocean_assert(offset.isEqual(*this * reference, NumericT<T>::weakEps()));
395}
396
397template <typename T>
399{
400 ocean_assert(quaternion.isValid());
401
402 const T invFactor = NumericT<T>::sqrt(T(1.0) - quaternion.w() * quaternion.w());
403
404 if (NumericT<T>::isEqualEps(invFactor))
405 {
406 values_[0] = T(0.0);
407 values_[1] = T(1.0);
408 values_[2] = T(0.0);
409 values_[3] = T(0.0);
410
411 return;
412 }
413
414 const T factor = T(1.0) / invFactor;
415
416 VectorT3<T> axis(quaternion.x() * factor, quaternion.y() * factor, quaternion.z() * factor);
417 axis.normalize();
418
419 values_[0] = axis[0];
420 values_[1] = axis[1];
421 values_[2] = axis[2];
422
423 values_[3] = T(2.0) * NumericT<T>::acos(quaternion.w());
424
425 ocean_assert(isValid());
426}
427
428template <typename T>
430{
431 ocean_assert(euler.isValid());
432
433 *this = RotationT(QuaternionT<T>(euler));
434 ocean_assert(isValid());
435}
436
437template <typename T>
439{
440 const T cosValue = (matrix.trace() - T(1.0)) * T(0.5);
441
442 if (NumericT<T>::isInsideRange(T(-1.0), cosValue, T(1.0)) == false)
443 {
444 ocean_assert(false && "Invalid rotation matrix, containing scale.");
445 }
446
447 if (NumericT<T>::isEqual(cosValue, T(1.0)))
448 {
449 values_[0] = T(0.0);
450 values_[1] = T(1.0);
451 values_[2] = T(0.0);
452 values_[3] = T(0.0);
453 }
454 else
455 {
456 VectorT3<T> axis;
457
458 if (NumericT<T>::isEqual(cosValue, T(-1.0)))
459 {
460 unsigned int select = 0;
461 T maximum = matrix(0, 0);
462
463 if (maximum < matrix(1, 1))
464 {
465 select = 1;
466 }
467 if (maximum < matrix(2, 2))
468 {
469 select = 2;
470 }
471
472 switch (select)
473 {
474 case 0:
475 {
476 axis(0) = T(0.5) * sqrt(matrix(0, 0) - matrix(1, 1) - matrix(2, 2) + T(1.0));
477 T factor = T(0.5) / axis(0);
478
479 axis(1) = matrix(0, 1) * factor;
480 axis(2) = matrix(0, 2) * factor;
481 break;
482 }
483
484 case 1:
485 {
486 axis(1) = T(0.5) * sqrt(matrix(1, 1) - matrix(0, 0) - matrix(2, 2) + T(1.0));
487 T factor = T(0.5) / axis(1);
488
489 axis(0) = matrix(0, 1) * factor;
490 axis(2) = matrix(1, 2) * factor;
491 break;
492 }
493
494 case 2:
495 {
496 axis(2) = T(0.5) * sqrt(matrix(2, 2) - matrix(0, 0) - matrix(1, 1) + T(1.0));
497 T factor = T(0.5) / axis(2);
498
499 axis(0) = matrix(0, 2) * factor;
500 axis(1) = matrix(1, 2) * factor;
501 break;
502 }
503
504 default:
505 ocean_assert(false);
506 break;
507 }
508
509 values_[3] = NumericT<T>::pi();
510 }
511 else
512 {
513 axis = VectorT3<T>(matrix(2, 1) - matrix(1, 2), matrix(0, 2) - matrix(2, 0), matrix(1, 0) - matrix(0, 1));
514 values_[3] = acos(cosValue);
515 }
516
517 axis.normalize();
518
519 values_[0] = axis(0);
520 values_[1] = axis(1);
521 values_[2] = axis(2);
522 }
523
524 ocean_assert(isValid());
525}
526
527template <typename T>
529{
530 ocean_assert(transformation.isValid());
531
532 const SquareMatrixT3<T> matrix(transformation.orthonormalRotationMatrix());
533 ocean_assert(NumericT<T>::isEqual(matrix.determinant(), T(1.0)));
534
535 const T cosValue = (matrix.trace() - T(1.0)) * T(0.5);
536 ocean_assert(NumericT<T>::isInsideRange(T(-1.0), cosValue, T(1.0)));
537
538 if (NumericT<T>::isEqual(cosValue, T(1.0)))
539 {
540 values_[0] = T(0.0);
541 values_[1] = T(1.0);
542 values_[2] = T(0.0);
543 values_[3] = T(0.0);
544 }
545 else
546 {
547 VectorT3<T> axis;
548
549 if (NumericT<T>::isEqual(cosValue, T(-1.0)))
550 {
551 unsigned int select = 0;
552 T maximum = matrix(0, 0);
553
554 if (maximum < matrix(1, 1))
555 {
556 select = 1;
557 }
558 if (maximum < matrix(2, 2))
559 {
560 select = 2;
561 }
562
563 switch (select)
564 {
565 case 0:
566 {
567 axis(0) = T(0.5) * NumericT<T>::sqrt(matrix(0, 0) - matrix(1, 1) - matrix(2, 2) + T(1.0));
568 T factor = T(0.5) / axis(0);
569
570 axis(1) = matrix(0, 1) * factor;
571 axis(2) = matrix(0, 2) * factor;
572 break;
573 }
574
575 case 1:
576 {
577 axis(1) = T(0.5) * NumericT<T>::sqrt(matrix(1, 1) - matrix(0, 0) - matrix(2, 2) + T(1.0));
578 T factor = T(0.5) / axis(1);
579
580 axis(0) = matrix(0, 1) * factor;
581 axis(2) = matrix(1, 2) * factor;
582 break;
583 }
584
585 case 2:
586 {
587 axis(2) = T(0.5) * NumericT<T>::sqrt(matrix(2, 2) - matrix(0, 0) - matrix(1, 1) + T(1.0));
588 T factor = T(0.5) / axis(2);
589
590 axis(0) = matrix(0, 2) * factor;
591 axis(1) = matrix(1, 2) * factor;
592 break;
593 }
594
595 default:
596 ocean_assert(false);
597 break;
598 }
599
600 values_[3] = NumericT<T>::pi();
601 }
602 else
603 {
604 axis =VectorT3<T>(matrix(2, 1) - matrix(1, 2), matrix(0, 2) - matrix(2, 0), matrix(1, 0) - matrix(0, 1));
605 values_[3] = NumericT<T>::acos(cosValue);
606 }
607
608 axis.normalize();
609
610 values_[0] = axis(0);
611 values_[1] = axis(1);
612 values_[2] = axis(2);
613 }
614
615 ocean_assert(isValid());
616}
617
618template <typename T>
619RotationT<T>::RotationT(const T* valueArray)
620{
621 memcpy(values_, valueArray, sizeof(T) * 4);
622
623 ocean_assert(isValid());
624}
625
626template <typename T>
628{
629 ocean_assert(NumericT<T>::isEqual(axis.length(), T(1.0)));
630
631 memcpy(values_, axis(), sizeof(T) * 3);
632
633 ocean_assert(isValid());
634}
635
636template <typename T>
637void RotationT<T>::setAngle(const T angle)
638{
639 if (angle > NumericT<T>::pi2())
640 {
641 values_[3] = NumericT<T>::fmod(angle, NumericT<T>::pi2());
642 }
643 else if (angle < T(0.0))
644 {
645 ocean_assert(NumericT<T>::fmod(angle, NumericT<T>::pi2()) < T(0.0));
646 values_[3] = NumericT<T>::pi2() + NumericT<T>::fmod(angle, NumericT<T>::pi2());
647 }
648 else
649 {
650 values_[3] = angle;
651 }
652
653 ocean_assert(isValid());
654}
655
656template <typename T>
658{
659 ocean_assert(isValid());
660 return RotationT<T>(-values_[0], -values_[1], -values_[2], values_[3]);
661}
662
663template <typename T>
665{
666 ocean_assert(isValid());
667 values_[0] = -values_[0];
668 values_[1] = -values_[1];
669 values_[2] = -values_[2];
670}
671
672template <typename T>
674{
675 return NumericT<T>::isEqual(axis().length(), T(1.0)) && NumericT<T>::isInsideRange(T(0.0), angle(), NumericT<T>::pi2());
676}
677
678template <typename T>
680{
681 ocean_assert(isValid() && right.isValid());
682
683 return (NumericT<T>::isEqual(values_[0], right.values_[0]) && NumericT<T>::isEqual(values_[1], right.values_[1])
684 && NumericT<T>::isEqual(values_[2], right.values_[2]) && NumericT<T>::isEqual(values_[3], right.values_[3]))
685 || (NumericT<T>::isEqual(values_[0], -right.values_[0]) && NumericT<T>::isEqual(values_[1], -right.values_[1])
686 && NumericT<T>::isEqual(values_[2], -right.values_[2]) && NumericT<T>::isEqual(values_[3] + right.values_[3], NumericT<T>::pi2()));
687}
688
689template <typename T>
691{
692 ocean_assert(isValid());
693 return RotationT<T>(-values_[0], -values_[1], -values_[2], values_[3]);
694}
695
696template <typename T>
698{
699 ocean_assert(isValid() && quaternion.isValid());
700 return RotationT<T>(QuaternionT<T>(*this) * quaternion);
701}
702
703template <typename T>
705{
706 ocean_assert(isValid() && quaternion.isValid());
707 *this = RotationT<T>(QuaternionT<T>(*this) * quaternion);
708
709 return *this;
710}
711
712template <typename T>
714{
715 ocean_assert(isValid() && right.isValid());
716 return RotationT<T>(QuaternionT<T>(*this) * QuaternionT<T>(right));
717}
718
719template <typename T>
721{
722 ocean_assert(isValid() && right.isValid());
723 *this = RotationT<T>(QuaternionT<T>(*this) * QuaternionT<T>(right));
724
725 return *this;
726}
727
728template <typename T>
730{
731 ocean_assert(isValid());
732 return QuaternionT<T>(*this) * vector;
733}
734
735template <typename T>
736inline const T* RotationT<T>::data() const
737{
738 return values_;
739}
740
741template <typename T>
743{
744 return values_;
745}
746
747template <typename T>
749{
750 return VectorT3<T>(values_);
751}
752
753template <typename T>
754inline T RotationT<T>::angle() const
755{
756 return values_[3];
757}
758
759template <typename T>
760inline bool RotationT<T>::operator!=(const RotationT& right) const
761{
762 return !(*this == right);
763}
764
765template <typename T>
766inline T RotationT<T>::operator()(unsigned int index) const
767{
768 ocean_assert(index < 4u);
769 return values_[index];
770}
771
772template <typename T>
773inline T& RotationT<T>::operator()(unsigned int index)
774{
775 ocean_assert(index < 4u);
776 return values_[index];
777}
778
779template <typename T>
780inline T RotationT<T>::operator[](unsigned int index) const
781{
782 ocean_assert(index < 4u);
783 return values_[index];
784}
785
786template <typename T>
787inline T& RotationT<T>::operator[](unsigned int index)
788{
789 ocean_assert(index < 4u);
790 return values_[index];
791}
792
793template <typename T>
794inline const T* RotationT<T>::operator()() const
795{
796 return values_;
797}
798
799template <typename T>
801{
802 return values_;
803}
804
805}
806
807#endif // META_OCEAN_MATH_ROTATION_H
This class implements an euler rotation with angles: yaw, pitch and roll.
Definition Euler.h:80
bool isValid() const
Returns whether the euler rotation holds valid parameters.
Definition Euler.h:351
This class implements a 4x4 homogeneous transformation matrix using floating point values with the pr...
Definition HomogenousMatrix4.h:110
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1806
SquareMatrixT3< T > orthonormalRotationMatrix() const
Returns the 3x3 orthonormal rotation matrix of the 4x4 transformation (by forcing a orthogonal and no...
Definition HomogenousMatrix4.h:1538
This class provides basic numeric functionalities.
Definition Numeric.h:57
static constexpr T pi2()
Returns 2*PI which is equivalent to 360 degree.
Definition Numeric.h:932
static constexpr bool isInsideRange(const T lower, const T value, const T upper, const T epsilon=NumericT< T >::eps())
Returns whether a value lies between a given range up to a provided epsilon border.
Definition Numeric.h:2875
static constexpr T pi()
Returns PI which is equivalent to 180 degree.
Definition Numeric.h:926
static T sqrt(const T value)
Returns the square root of a given value.
Definition Numeric.h:1533
static T fmod(const T valueA, const T valueB)
Returns the floating-point remainder of a given value.
Definition Numeric.h:1735
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition Numeric.h:2389
static T acos(const T value)
Returns the arccosine of a given value.
Definition Numeric.h:2910
This class implements a unit quaternion rotation.
Definition Quaternion.h:100
const T & x() const
Returns the x value of the quaternion.
Definition Quaternion.h:919
bool isValid() const
Returns whether this quaternion is a valid unit quaternion.
Definition Quaternion.h:901
const T & w() const
Returns the w value of the quaternion.
Definition Quaternion.h:907
const T & y() const
Returns the y value of the quaternion.
Definition Quaternion.h:931
const T & z() const
Returns the z value of the quaternion.
Definition Quaternion.h:943
This class implements a axis-angle rotation using floating point values.
Definition Rotation.h:79
RotationT()=default
Creates a rotation object with default values so that the rotation represents the identity rotation.
T Type
Definition of the used data type.
Definition Rotation.h:85
bool operator!=(const RotationT< T > &right) const
Returns whether two rotations are not identical up to a small epsilon.
Definition Rotation.h:760
bool operator==(const RotationT< T > &right) const
Returns whether two rotations are identical up to a small epsilon.
Definition Rotation.h:679
RotationT inverted() const
Returns the inverted rotation, this rotation must be valid.
Definition Rotation.h:657
VectorT3< T > axis() const
Returns the axis of the rotation.
Definition Rotation.h:748
const T * operator()() const
Access operator.
Definition Rotation.h:794
RotationT operator-() const
Returns the inverse rotation, this rotation must be valid.
Definition Rotation.h:690
void invert()
Inverts this rotation, this rotation must be valid.
Definition Rotation.h:664
T angle() const
Returns the angle of the rotation.
Definition Rotation.h:754
T operator[](unsigned int index) const
Element access operator.
Definition Rotation.h:780
void setAxis(const VectorT3< T > &axis)
Sets the axis of the rotation.
Definition Rotation.h:627
T values_[4]
The four values of the angle-axis rotation.
Definition Rotation.h:310
RotationT & operator*=(const QuaternionT< T > &quaternion)
Multiplies and assign two rotations, this rotation must be valid.
Definition Rotation.h:704
RotationT operator*(const QuaternionT< T > &quaternion) const
Multiplies two rotations, this rotation must be valid.
Definition Rotation.h:697
void setAngle(const T angle)
Sets the angle of the rotation.
Definition Rotation.h:637
const T * data() const
Returns a pointer to the internal values.
Definition Rotation.h:736
bool isValid() const
Returns whether this rotation has valid parameters.
Definition Rotation.h:673
This class implements a 3x3 square matrix.
Definition SquareMatrix3.h:88
T determinant() const
Returns the determinant of the matrix.
Definition SquareMatrix3.h:1283
T trace() const
Returns the trace of the matrix which is the sum of the diagonal elements.
Definition SquareMatrix3.h:1291
This class implements a vector with three elements.
Definition Vector3.h:97
VectorT3< T > perpendicular() const
Returns a vector that is perpendicular to this vector.
Definition Vector3.h:768
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:824
bool normalize()
Normalizes this vector.
Definition Vector3.h:659
VectorT3< T > cross(const VectorT3< T > &vector) const
Returns the cross product of two vectors.
Definition Vector3.h:609
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:812
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:836
bool isEqual(const VectorT3< T > &vector, const T eps) const
Returns whether two vectors are equal up to a specified epsilon.
Definition Vector3.h:879
T length() const
Returns the length of the vector.
Definition Vector3.h:676
T angle(const VectorT3< T > &right) const
Returns the angle between this vector and a second vectors.
Definition Vector3.h:700
std::vector< RotationT< T > > RotationsT
Definition of a typename alias for vectors with RotationT objects.
Definition Rotation.h:60
RotationT< Scalar > Rotation
Definition of the Rotation object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag either with ...
Definition Rotation.h:38
RotationT< float > RotationF
Instantiation of the RotationT template class using a single precision float data type.
Definition Rotation.h:52
std::vector< Rotation > Rotations
Definition of a vector holding rotation objects.
Definition Rotation.h:67
RotationT< double > RotationD
Instantiation of the RotationT template class using a double precision float data type.
Definition Rotation.h:45
The namespace covering the entire Ocean framework.
Definition Accessor.h:15