8 #ifndef META_OCEAN_MATH_ROTATION_H
9 #define META_OCEAN_MATH_ROTATION_H
25 template <
typename T>
class SquareMatrixT3;
28 template <
typename T>
class HomogenousMatrixT4;
31 template <
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;
313 template <
typename T>
324 else if (angle < T(0.0))
334 ocean_assert(isValid());
337 template <
typename T>
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());
361 template <
typename T>
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());
397 template <
typename T>
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());
428 template <
typename T>
434 ocean_assert(isValid());
437 template <
typename T>
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;
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);
515 values_[0] = axis(0);
516 values_[1] = axis(1);
517 values_[2] = axis(2);
520 ocean_assert(isValid());
523 template <
typename T>
526 ocean_assert(transformation.
isValid());
531 const T cosValue = (matrix.
trace() - T(1.0)) * T(0.5);
547 unsigned int select = 0;
548 T maximum = matrix(0, 0);
550 if (maximum < matrix(1, 1))
554 if (maximum < matrix(2, 2))
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);
566 axis(1) = matrix(0, 1) * factor;
567 axis(2) = matrix(0, 2) * factor;
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);
576 axis(0) = matrix(0, 1) * factor;
577 axis(2) = matrix(1, 2) * factor;
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);
586 axis(0) = matrix(0, 2) * factor;
587 axis(1) = matrix(1, 2) * factor;
596 axis =
VectorT3<T>(matrix(2, 1) - matrix(1, 2), matrix(0, 2) - matrix(2, 0), matrix(1, 0) - matrix(0, 1));
602 values_[0] = axis(0);
603 values_[1] = axis(1);
604 values_[2] = axis(2);
607 ocean_assert(isValid());
610 template <
typename T>
613 memcpy(values_, valueArray,
sizeof(T) * 4);
615 ocean_assert(isValid());
618 template <
typename T>
623 memcpy(values_, axis(),
sizeof(T) * 3);
625 ocean_assert(isValid());
628 template <
typename T>
635 else if (angle < T(0.0))
645 ocean_assert(isValid());
648 template <
typename T>
651 ocean_assert(isValid());
652 return RotationT<T>(-values_[0], -values_[1], -values_[2], values_[3]);
655 template <
typename T>
658 ocean_assert(isValid());
659 values_[0] = -values_[0];
660 values_[1] = -values_[1];
661 values_[2] = -values_[2];
664 template <
typename T>
670 template <
typename T>
673 ocean_assert(isValid() && right.
isValid());
681 template <
typename T>
684 ocean_assert(isValid());
685 return RotationT<T>(-values_[0], -values_[1], -values_[2], values_[3]);
688 template <
typename T>
691 ocean_assert(isValid() && quaternion.
isValid());
695 template <
typename T>
698 ocean_assert(isValid() && quaternion.
isValid());
704 template <
typename T>
707 ocean_assert(isValid() && right.
isValid());
711 template <
typename T>
714 ocean_assert(isValid() && right.
isValid());
720 template <
typename T>
723 ocean_assert(isValid());
727 template <
typename T>
733 template <
typename T>
739 template <
typename T>
745 template <
typename T>
751 template <
typename T>
754 return !(*
this == right);
757 template <
typename T>
760 ocean_assert(index < 4u);
761 return values_[index];
764 template <
typename T>
767 ocean_assert(index < 4u);
768 return values_[index];
771 template <
typename T>
774 ocean_assert(index < 4u);
775 return values_[index];
778 template <
typename T>
781 ocean_assert(index < 4u);
782 return values_[index];
785 template <
typename T>
791 template <
typename T>
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