8#ifndef META_OCEAN_MATH_ROTATION_H
9#define META_OCEAN_MATH_ROTATION_H
25template <
typename T>
class SquareMatrixT3;
28template <
typename T>
class HomogenousMatrixT4;
31template <
typename T>
class RotationT;
173 inline const T*
data()
const;
191 inline T
angle()
const;
272 inline T
operator()(
unsigned int index)
const;
286 inline T
operator[](
unsigned int index)
const;
324 else if (angle < T(0.0))
334 ocean_assert(isValid());
340 values_[0] = axis[0];
341 values_[1] = axis[1];
342 values_[2] = axis[2];
348 else if (angle < T(0.0))
358 ocean_assert(isValid());
367 if (reference == offset)
374 else if (reference == -offset)
378 values_[0] = perpendicular[0];
379 values_[1] = perpendicular[1];
380 values_[2] = perpendicular[2];
387 values_[0] = axis.
x();
388 values_[1] = axis.
y();
389 values_[2] = axis.
z();
390 values_[3] = reference.
angle(offset);
393 ocean_assert(isValid());
400 ocean_assert(quaternion.
isValid());
414 const T factor = T(1.0) / invFactor;
416 VectorT3<T> axis(quaternion.
x() * factor, quaternion.
y() * factor, quaternion.
z() * factor);
419 values_[0] = axis[0];
420 values_[1] = axis[1];
421 values_[2] = axis[2];
425 ocean_assert(isValid());
434 ocean_assert(isValid());
440 const T cosValue = (matrix.
trace() - T(1.0)) * T(0.5);
444 ocean_assert(
false &&
"Invalid rotation matrix, containing scale.");
460 unsigned int select = 0;
461 T maximum = matrix(0, 0);
463 if (maximum < matrix(1, 1))
467 if (maximum < matrix(2, 2))
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);
479 axis(1) = matrix(0, 1) * factor;
480 axis(2) = matrix(0, 2) * factor;
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);
489 axis(0) = matrix(0, 1) * factor;
490 axis(2) = matrix(1, 2) * factor;
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);
499 axis(0) = matrix(0, 2) * factor;
500 axis(1) = matrix(1, 2) * factor;
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);
519 values_[0] = axis(0);
520 values_[1] = axis(1);
521 values_[2] = axis(2);
524 ocean_assert(isValid());
530 ocean_assert(transformation.
isValid());
535 const T cosValue = (matrix.
trace() - T(1.0)) * T(0.5);
551 unsigned int select = 0;
552 T maximum = matrix(0, 0);
554 if (maximum < matrix(1, 1))
558 if (maximum < matrix(2, 2))
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);
570 axis(1) = matrix(0, 1) * factor;
571 axis(2) = matrix(0, 2) * factor;
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);
580 axis(0) = matrix(0, 1) * factor;
581 axis(2) = matrix(1, 2) * factor;
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);
590 axis(0) = matrix(0, 2) * factor;
591 axis(1) = matrix(1, 2) * factor;
604 axis =
VectorT3<T>(matrix(2, 1) - matrix(1, 2), matrix(0, 2) - matrix(2, 0), matrix(1, 0) - matrix(0, 1));
610 values_[0] = axis(0);
611 values_[1] = axis(1);
612 values_[2] = axis(2);
615 ocean_assert(isValid());
621 memcpy(values_, valueArray,
sizeof(T) * 4);
623 ocean_assert(isValid());
631 memcpy(values_, axis(),
sizeof(T) * 3);
633 ocean_assert(isValid());
643 else if (angle < T(0.0))
653 ocean_assert(isValid());
659 ocean_assert(isValid());
660 return RotationT<T>(-values_[0], -values_[1], -values_[2], values_[3]);
666 ocean_assert(isValid());
667 values_[0] = -values_[0];
668 values_[1] = -values_[1];
669 values_[2] = -values_[2];
681 ocean_assert(isValid() && right.
isValid());
692 ocean_assert(isValid());
693 return RotationT<T>(-values_[0], -values_[1], -values_[2], values_[3]);
699 ocean_assert(isValid() && quaternion.
isValid());
706 ocean_assert(isValid() && quaternion.
isValid());
715 ocean_assert(isValid() && right.
isValid());
722 ocean_assert(isValid() && right.
isValid());
731 ocean_assert(isValid());
762 return !(*
this == right);
768 ocean_assert(index < 4u);
769 return values_[index];
775 ocean_assert(index < 4u);
776 return values_[index];
782 ocean_assert(index < 4u);
783 return values_[index];
789 ocean_assert(index < 4u);
790 return values_[index];
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