8#ifndef META_OCEAN_MATH_ROTATION_H
9#define META_OCEAN_MATH_ROTATION_H
21template <
typename T>
class HomogenousMatrixT4;
23template <
typename T>
class RotationT;
25template <
typename T>
class SquareMatrixT3;
167 inline const T*
data()
const;
185 inline T
angle()
const;
274 inline T
operator()(
unsigned int index)
const;
288 inline T
operator[](
unsigned int index)
const;
336 ocean_assert(isValid());
341 RotationT<T>(axis.x(), axis.y(), axis.z(), angle)
348 RotationT<T>(left_R_right(offset, reference))
356 ocean_assert(quaternion.
isValid());
370 const T factor = T(1.0) / invFactor;
372 VectorT3<T> axis(quaternion.
x() * factor, quaternion.
y() * factor, quaternion.
z() * factor);
375 values_[0] = axis[0];
376 values_[1] = axis[1];
377 values_[2] = axis[2];
381 ocean_assert(isValid());
390 ocean_assert(isValid());
396 const T cosValue = (matrix.
trace() - T(1.0)) * T(0.5);
400 ocean_assert(
false &&
"Invalid rotation matrix, containing scale.");
416 unsigned int select = 0;
417 T maximum = matrix(0, 0);
419 if (maximum < matrix(1, 1))
422 maximum = matrix(1, 1);
424 if (maximum < matrix(2, 2))
433 axis(0) = T(0.5) *
NumericT<T>::sqrt(matrix(0, 0) - matrix(1, 1) - matrix(2, 2) + T(1.0));
434 T factor = T(0.5) / axis(0);
436 axis(1) = matrix(0, 1) * factor;
437 axis(2) = matrix(0, 2) * factor;
443 axis(1) = T(0.5) *
NumericT<T>::sqrt(matrix(1, 1) - matrix(0, 0) - matrix(2, 2) + T(1.0));
444 T factor = T(0.5) / axis(1);
446 axis(0) = matrix(0, 1) * factor;
447 axis(2) = matrix(1, 2) * factor;
453 axis(2) = T(0.5) *
NumericT<T>::sqrt(matrix(2, 2) - matrix(0, 0) - matrix(1, 1) + T(1.0));
454 T factor = T(0.5) / axis(2);
456 axis(0) = matrix(0, 2) * factor;
457 axis(1) = matrix(1, 2) * factor;
470 axis =
VectorT3<T>(matrix(2, 1) - matrix(1, 2), matrix(0, 2) - matrix(2, 0), matrix(1, 0) - matrix(0, 1));
476 values_[0] = axis(0);
477 values_[1] = axis(1);
478 values_[2] = axis(2);
481 ocean_assert(isValid());
487 ocean_assert(transformation.
isValid());
498 ocean_assert(valueArray !=
nullptr);
500 values_[0] = valueArray[0];
501 values_[1] = valueArray[1];
502 values_[2] = valueArray[2];
506 ocean_assert(isValid());
512 ocean_assert(axis.
isUnit());
514 values_[0] = axis[0];
515 values_[1] = axis[1];
516 values_[2] = axis[2];
518 ocean_assert(isValid());
526 ocean_assert(isValid());
532 ocean_assert(isValid());
533 return RotationT<T>(-values_[0], -values_[1], -values_[2], values_[3]);
539 ocean_assert(isValid());
541 values_[0] = -values_[0];
542 values_[1] = -values_[1];
543 values_[2] = -values_[2];
555 ocean_assert(isValid() && rotation.
isValid());
556 ocean_assert(eps >= T(0.0));
565 ocean_assert(isValid() && right.
isValid());
567 return isEqual(right);
573 ocean_assert(isValid());
575 return RotationT<T>(-values_[0], -values_[1], -values_[2], values_[3]);
581 ocean_assert(isValid() && quaternion.
isValid());
591 ocean_assert(isValid() && quaternion.
isValid());
603 ocean_assert(isValid() && right.
isValid());
613 ocean_assert(isValid() && right.
isValid());
625 ocean_assert(isValid());
657 return !(*
this == right);
663 ocean_assert(index < 4u);
665 return values_[index];
671 ocean_assert(index < 4u);
673 return values_[index];
679 ocean_assert(index < 4u);
681 return values_[index];
687 ocean_assert(index < 4u);
689 return values_[index];
716 else if (left == -right)
724 const T angle = right.
angle(left);
727 ocean_assert(result.
isValid());
This class implements an euler rotation with angles: yaw, pitch and roll.
Definition Euler.h:82
bool isValid() const
Returns whether the euler rotation holds valid parameters.
Definition Euler.h:360
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 T angleAdjustPositive(const T angle)
Adjusts an arbitrary angle into the range of [0.0, 2PI).
Definition Numeric.h:1770
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:2881
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:1537
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition Numeric.h:2395
static bool angleIsEqual(const T angleA, const T angleB)
Returns whether two angles represent the same angle up to a small epsilon.
Definition Numeric.h:1825
static T acos(const T value)
Returns the arccosine of a given value.
Definition Numeric.h:2916
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:900
bool isValid() const
Returns whether this quaternion is a valid unit quaternion.
Definition Quaternion.h:882
const T & w() const
Returns the w value of the quaternion.
Definition Quaternion.h:888
QuaternionT< T > normalized() const
Returns the normalized quaternion.
Definition Quaternion.h:682
const T & y() const
Returns the y value of the quaternion.
Definition Quaternion.h:912
const T & z() const
Returns the z value of the quaternion.
Definition Quaternion.h:924
This class implements a axis-angle rotation using floating point values.
Definition Rotation.h:73
RotationT()=default
Creates a rotation object with default values so that the rotation represents the identity rotation.
static RotationT< T > left_R_right(const VectorT3< T > &left, const VectorT3< T > &right)
Returns a rotation object based on two given unit vectors.
Definition Rotation.h:705
bool isEqual(const RotationT< T > &rotation, const T eps=NumericT< T >::eps()) const
Returns whether two rotations are equal up to a specified epsilon.
Definition Rotation.h:553
bool operator!=(const RotationT< T > &right) const
Returns whether two rotations are not identical up to a small epsilon.
Definition Rotation.h:655
bool operator==(const RotationT< T > &right) const
Returns whether two rotations are identical up to a small epsilon.
Definition Rotation.h:563
RotationT inverted() const
Returns the inverted rotation, this rotation must be valid.
Definition Rotation.h:530
VectorT3< T > axis() const
Returns the axis of the rotation.
Definition Rotation.h:643
const T * operator()() const
Access operator.
Definition Rotation.h:693
RotationT operator-() const
Returns the inverse rotation, this rotation must be valid.
Definition Rotation.h:571
void invert()
Inverts this rotation, this rotation must be valid.
Definition Rotation.h:537
T angle() const
Returns the angle of the rotation.
Definition Rotation.h:649
T Type
Definition of the used data type.
Definition Rotation.h:79
T operator[](unsigned int index) const
Element access operator.
Definition Rotation.h:677
void setAxis(const VectorT3< T > &axis)
Sets the axis of the rotation.
Definition Rotation.h:510
T values_[4]
The four values of the angle-axis rotation.
Definition Rotation.h:324
RotationT & operator*=(const QuaternionT< T > &quaternion)
Multiplies and assign two rotations, this rotation must be valid.
Definition Rotation.h:589
RotationT operator*(const QuaternionT< T > &quaternion) const
Multiplies two rotations, this rotation must be valid.
Definition Rotation.h:579
void setAngle(const T angle)
Sets the angle of the rotation.
Definition Rotation.h:522
const T * data() const
Returns a pointer to the internal values.
Definition Rotation.h:631
bool isValid() const
Returns whether this rotation has valid parameters.
Definition Rotation.h:547
This class implements a 3x3 square matrix.
Definition SquareMatrix3.h:89
T determinant() const
Returns the determinant of the matrix.
Definition SquareMatrix3.h:1284
T trace() const
Returns the trace of the matrix which is the sum of the diagonal elements.
Definition SquareMatrix3.h:1292
This class implements a vector with three elements.
Definition Vector3.h:97
bool isUnit(const T eps=NumericT< T >::eps()) const
Returns whether this vector is a unit vector (whether the vector has the length 1).
Definition Vector3.h:873
VectorT3< T > perpendicular() const
Returns a vector that is perpendicular to this vector.
Definition Vector3.h:768
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
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:54
std::vector< Rotation > Rotations
Definition of a vector holding rotation objects.
Definition Rotation.h:61
The namespace covering the entire Ocean framework.
Definition Accessor.h:15