Ocean
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"
14 #include "ocean/math/Quaternion.h"
16 
17 #include "ocean/base/Exception.h"
18 
19 #include <vector>
20 
21 namespace Ocean
22 {
23 
24 // Forward declaration.
25 template <typename T> class SquareMatrixT3;
26 
27 // Forward declaration.
28 template <typename T> class HomogenousMatrixT4;
29 
30 // Forward declaration.
31 template <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  */
59 template <typename T>
60 using RotationsT = std::vector<RotationT<T>>;
61 
62 /**
63  * Definition of a vector holding rotation objects.
64  * @see Rotation
65  * @ingroup math
66  */
67 typedef 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  */
77 template <typename T>
78 class RotationT
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 
313 template <typename T>
314 RotationT<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 
337 template <typename T>
338 RotationT<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 
361 template <typename T>
362 RotationT<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 
397 template <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 
428 template <typename T>
430 {
431  ocean_assert(euler.isValid());
432 
433  *this = RotationT(QuaternionT<T>(euler));
434  ocean_assert(isValid());
435 }
436 
437 template <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 
505  values_[3] = NumericT<T>::pi();
506  }
507  else
508  {
509  axis = VectorT3<T>(matrix(2, 1) - matrix(1, 2), matrix(0, 2) - matrix(2, 0), matrix(1, 0) - matrix(0, 1));
510  values_[3] = acos(cosValue);
511  }
512 
513  axis.normalize();
514 
515  values_[0] = axis(0);
516  values_[1] = axis(1);
517  values_[2] = axis(2);
518  }
519 
520  ocean_assert(isValid());
521 }
522 
523 template <typename T>
525 {
526  ocean_assert(transformation.isValid());
527 
528  const SquareMatrixT3<T> matrix(transformation.orthonormalRotationMatrix());
529  ocean_assert(NumericT<T>::isEqual(matrix.determinant(), T(1.0)));
530 
531  const T cosValue = (matrix.trace() - T(1.0)) * T(0.5);
532  ocean_assert(NumericT<T>::isInsideRange(T(-1.0), cosValue, T(1.0)));
533 
534  if (NumericT<T>::isEqual(cosValue, T(1.0)))
535  {
536  values_[0] = T(0.0);
537  values_[1] = T(1.0);
538  values_[2] = T(0.0);
539  values_[3] = T(0.0);
540  }
541  else
542  {
543  VectorT3<T> axis;
544 
545  if (NumericT<T>::isEqual(cosValue, T(-1.0)))
546  {
547  unsigned int select = 0;
548  T maximum = matrix(0, 0);
549 
550  if (maximum < matrix(1, 1))
551  {
552  select = 1;
553  }
554  if (maximum < matrix(2, 2))
555  {
556  select = 2;
557  }
558 
559  switch (select)
560  {
561  case 0:
562  {
563  axis(0) = T(0.5) * NumericT<T>::sqrt(matrix(0, 0) - matrix(1, 1) - matrix(2, 2) + T(1.0));
564  T factor = T(0.5) / axis(0);
565 
566  axis(1) = matrix(0, 1) * factor;
567  axis(2) = matrix(0, 2) * factor;
568  break;
569  }
570 
571  case 1:
572  {
573  axis(1) = T(0.5) * NumericT<T>::sqrt(matrix(1, 1) - matrix(0, 0) - matrix(2, 2) + T(1.0));
574  T factor = T(0.5) / axis(1);
575 
576  axis(0) = matrix(0, 1) * factor;
577  axis(2) = matrix(1, 2) * factor;
578  break;
579  }
580 
581  case 2:
582  {
583  axis(2) = T(0.5) * NumericT<T>::sqrt(matrix(2, 2) - matrix(0, 0) - matrix(1, 1) + T(1.0));
584  T factor = T(0.5) / axis(2);
585 
586  axis(0) = matrix(0, 2) * factor;
587  axis(1) = matrix(1, 2) * factor;
588  break;
589  }
590  }
591 
592  values_[3] = NumericT<T>::pi();
593  }
594  else
595  {
596  axis =VectorT3<T>(matrix(2, 1) - matrix(1, 2), matrix(0, 2) - matrix(2, 0), matrix(1, 0) - matrix(0, 1));
597  values_[3] = NumericT<T>::acos(cosValue);
598  }
599 
600  axis.normalize();
601 
602  values_[0] = axis(0);
603  values_[1] = axis(1);
604  values_[2] = axis(2);
605  }
606 
607  ocean_assert(isValid());
608 }
609 
610 template <typename T>
611 RotationT<T>::RotationT(const T* valueArray)
612 {
613  memcpy(values_, valueArray, sizeof(T) * 4);
614 
615  ocean_assert(isValid());
616 }
617 
618 template <typename T>
620 {
621  ocean_assert(NumericT<T>::isEqual(axis.length(), T(1.0)));
622 
623  memcpy(values_, axis(), sizeof(T) * 3);
624 
625  ocean_assert(isValid());
626 }
627 
628 template <typename T>
629 void RotationT<T>::setAngle(const T angle)
630 {
631  if (angle > NumericT<T>::pi2())
632  {
633  values_[3] = NumericT<T>::fmod(angle, NumericT<T>::pi2());
634  }
635  else if (angle < T(0.0))
636  {
637  ocean_assert(NumericT<T>::fmod(angle, NumericT<T>::pi2()) < T(0.0));
638  values_[3] = NumericT<T>::pi2() + NumericT<T>::fmod(angle, NumericT<T>::pi2());
639  }
640  else
641  {
642  values_[3] = angle;
643  }
644 
645  ocean_assert(isValid());
646 }
647 
648 template <typename T>
650 {
651  ocean_assert(isValid());
652  return RotationT<T>(-values_[0], -values_[1], -values_[2], values_[3]);
653 }
654 
655 template <typename T>
657 {
658  ocean_assert(isValid());
659  values_[0] = -values_[0];
660  values_[1] = -values_[1];
661  values_[2] = -values_[2];
662 }
663 
664 template <typename T>
666 {
667  return NumericT<T>::isEqual(axis().length(), T(1.0)) && NumericT<T>::isInsideRange(T(0.0), angle(), NumericT<T>::pi2());
668 }
669 
670 template <typename T>
671 bool RotationT<T>::operator==(const RotationT<T>& right) const
672 {
673  ocean_assert(isValid() && right.isValid());
674 
675  return (NumericT<T>::isEqual(values_[0], right.values_[0]) && NumericT<T>::isEqual(values_[1], right.values_[1])
676  && NumericT<T>::isEqual(values_[2], right.values_[2]) && NumericT<T>::isEqual(values_[3], right.values_[3]))
677  || (NumericT<T>::isEqual(values_[0], -right.values_[0]) && NumericT<T>::isEqual(values_[1], -right.values_[1])
678  && NumericT<T>::isEqual(values_[2], -right.values_[2]) && NumericT<T>::isEqual(values_[3] + right.values_[3], NumericT<T>::pi2()));
679 }
680 
681 template <typename T>
683 {
684  ocean_assert(isValid());
685  return RotationT<T>(-values_[0], -values_[1], -values_[2], values_[3]);
686 }
687 
688 template <typename T>
690 {
691  ocean_assert(isValid() && quaternion.isValid());
692  return RotationT<T>(QuaternionT<T>(*this) * quaternion);
693 }
694 
695 template <typename T>
697 {
698  ocean_assert(isValid() && quaternion.isValid());
699  *this = RotationT<T>(QuaternionT<T>(*this) * quaternion);
700 
701  return *this;
702 }
703 
704 template <typename T>
706 {
707  ocean_assert(isValid() && right.isValid());
708  return RotationT<T>(QuaternionT<T>(*this) * QuaternionT<T>(right));
709 }
710 
711 template <typename T>
713 {
714  ocean_assert(isValid() && right.isValid());
715  *this = RotationT<T>(QuaternionT<T>(*this) * QuaternionT<T>(right));
716 
717  return *this;
718 }
719 
720 template <typename T>
722 {
723  ocean_assert(isValid());
724  return QuaternionT<T>(*this) * vector;
725 }
726 
727 template <typename T>
728 inline const T* RotationT<T>::data() const
729 {
730  return values_;
731 }
732 
733 template <typename T>
735 {
736  return values_;
737 }
738 
739 template <typename T>
741 {
742  return VectorT3<T>(values_);
743 }
744 
745 template <typename T>
746 inline T RotationT<T>::angle() const
747 {
748  return values_[3];
749 }
750 
751 template <typename T>
752 inline bool RotationT<T>::operator!=(const RotationT& right) const
753 {
754  return !(*this == right);
755 }
756 
757 template <typename T>
758 inline T RotationT<T>::operator()(unsigned int index) const
759 {
760  ocean_assert(index < 4u);
761  return values_[index];
762 }
763 
764 template <typename T>
765 inline T& RotationT<T>::operator()(unsigned int index)
766 {
767  ocean_assert(index < 4u);
768  return values_[index];
769 }
770 
771 template <typename T>
772 inline T RotationT<T>::operator[](unsigned int index) const
773 {
774  ocean_assert(index < 4u);
775  return values_[index];
776 }
777 
778 template <typename T>
779 inline T& RotationT<T>::operator[](unsigned int index)
780 {
781  ocean_assert(index < 4u);
782  return values_[index];
783 }
784 
785 template <typename T>
786 inline const T* RotationT<T>::operator()() const
787 {
788  return values_;
789 }
790 
791 template <typename T>
793 {
794  return values_;
795 }
796 
797 }
798 
799 #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:2872
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:2386
static T acos(const T value)
Returns the arccosine of a given value.
Definition: Numeric.h:2907
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:917
bool isValid() const
Returns whether this quaternion is a valid unit quaternion.
Definition: Quaternion.h:899
const T & w() const
Returns the w value of the quaternion.
Definition: Quaternion.h:905
const T & y() const
Returns the y value of the quaternion.
Definition: Quaternion.h:929
const T & z() const
Returns the z value of the quaternion.
Definition: Quaternion.h:941
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:752
bool operator==(const RotationT< T > &right) const
Returns whether two rotations are identical up to a small epsilon.
Definition: Rotation.h:671
RotationT inverted() const
Returns the inverted rotation, this rotation must be valid.
Definition: Rotation.h:649
VectorT3< T > axis() const
Returns the axis of the rotation.
Definition: Rotation.h:740
const T * operator()() const
Access operator.
Definition: Rotation.h:786
RotationT operator-() const
Returns the inverse rotation, this rotation must be valid.
Definition: Rotation.h:682
void invert()
Inverts this rotation, this rotation must be valid.
Definition: Rotation.h:656
T angle() const
Returns the angle of the rotation.
Definition: Rotation.h:746
T operator[](unsigned int index) const
Element access operator.
Definition: Rotation.h:772
void setAxis(const VectorT3< T > &axis)
Sets the axis of the rotation.
Definition: Rotation.h:619
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:696
RotationT operator*(const QuaternionT< T > &quaternion) const
Multiplies two rotations, this rotation must be valid.
Definition: Rotation.h:689
void setAngle(const T angle)
Sets the angle of the rotation.
Definition: Rotation.h:629
const T * data() const
Returns a pointer to the internal values.
Definition: Rotation.h:728
bool isValid() const
Returns whether this rotation has valid parameters.
Definition: Rotation.h:665
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:756
const T & y() const noexcept
Returns the y value.
Definition: Vector3.h:812
bool normalize()
Normalizes this vector.
Definition: Vector3.h:647
VectorT3< T > cross(const VectorT3< T > &vector) const
Returns the cross product of two vectors.
Definition: Vector3.h:597
const T & x() const noexcept
Returns the x value.
Definition: Vector3.h:800
const T & z() const noexcept
Returns the z value.
Definition: Vector3.h:824
bool isEqual(const VectorT3< T > &vector, const T eps) const
Returns whether two vectors are equal up to a specified epsilon.
Definition: Vector3.h:867
T length() const
Returns the length of the vector.
Definition: Vector3.h:664
T angle(const VectorT3< T > &right) const
Returns the angle between this vector and a second vectors.
Definition: Vector3.h:688
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:31
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