template<class T>
Quaternion class
Quaternion.
Template parameters | |
---|---|
T | Underlying data type |
Contents
Represents 3D rotation. See 2D and 3D transformations for brief introduction.
Public types
- using Type = T
- Underlying data type.
Public static functions
- static auto rotation(Rad<T> angle, const Vector3<T>& normalizedAxis) -> Quaternion<T>
- Rotation quaternion.
- static auto fromMatrix(const Matrix3x3<T>& matrix) -> Quaternion<T>
- Create quaternion from rotation matrix.
Constructors, destructors, conversion operators
- Quaternion(IdentityInitT = IdentityInit) constexpr noexcept
- Default constructor.
- Quaternion(ZeroInitT) explicit constexpr noexcept
- Construct zero-initialized quaternion.
- Quaternion(NoInitT) explicit noexcept
- Construct without initializing the contents.
- Quaternion(const Vector3<T>& vector, T scalar) constexpr noexcept
- Construct quaternion from vector and scalar.
- Quaternion(const Vector3<T>& vector) explicit constexpr noexcept
- Construct quaternion from vector.
-
template<class U>Quaternion(const Quaternion<U>& other) explicit constexpr noexcept
- Construct dual complex number from another of different type.
-
template<class U, class V = decltype(Implementation::QuaternionConverter<T, U>::from(std::Quaternion(const U& other) explicit constexpr
declval<U>()))> - Construct quaternion from external representation.
- Quaternion(const Quaternion<T>&) noexcept defaulted constexpr
- Copy constructor.
-
template<class U, class V = decltype(Implementation::QuaternionConverter<T, U>::to(std::operator U() const explicit constexpr
declval<Quaternion<T>>()))> - Convert quaternion to external representation.
Public functions
- auto operator==(const Quaternion<T>& other) const -> bool
- Equality comparison.
- auto operator!=(const Quaternion<T>& other) const -> bool
- Non-equality comparison.
- auto isNormalized() const -> bool
- Whether the quaternion is normalized.
- auto vector() const -> const Vector3<T> constexpr
- Vector part.
- auto scalar() const -> T constexpr
- Scalar part.
- auto angle() const -> Rad<T>
- Rotation angle of unit quaternion.
- auto axis() const -> Vector3<T>
- Rotation axis of unit quaternion.
- auto toMatrix() const -> Matrix3x3<T>
- Convert quaternion to rotation matrix.
- auto operator+=(const Quaternion<T>& other) -> Quaternion<T>&
- Add and assign quaternion.
- auto operator+(const Quaternion<T>& other) const -> Quaternion<T>
- Add quaternion.
- auto operator-() const -> Quaternion<T>
- Negated quaternion.
- auto operator-=(const Quaternion<T>& other) -> Quaternion<T>&
- Subtract and assign quaternion.
- auto operator-(const Quaternion<T>& other) const -> Quaternion<T>
- Subtract quaternion.
- auto operator*=(T scalar) -> Quaternion<T>&
- Multiply with scalar and assign.
- auto operator*(T scalar) const -> Quaternion<T>
- Multiply with scalar.
- auto operator/=(T scalar) -> Quaternion<T>&
- Divide with scalar and assign.
- auto operator/(T scalar) const -> Quaternion<T>
- Divide with scalar.
- auto operator*(const Quaternion<T>& other) const -> Quaternion<T>
- Multiply with quaternion.
- auto dot() const -> T
- Dot product of the quaternion.
- auto length() const -> T
- Quaternion length.
- auto normalized() const -> Quaternion<T>
- Normalized quaternion (of unit length)
- auto conjugated() const -> Quaternion<T>
- Conjugated quaternion.
- auto inverted() const -> Quaternion<T>
- Inverted quaternion.
- auto invertedNormalized() const -> Quaternion<T>
- Inverted normalized quaternion.
- auto transformVector(const Vector3<T>& vector) const -> Vector3<T>
- Rotate vector with quaternion.
- auto transformVectorNormalized(const Vector3<T>& vector) const -> Vector3<T>
- Rotate vector with normalized quaternion.
Function documentation
template<class T>
static Quaternion<T> Magnum:: Math:: Quaternion<T>:: rotation(Rad<T> angle,
const Vector3<T>& normalizedAxis)
Rotation quaternion.
Parameters | |
---|---|
angle | Rotation angle (counterclockwise) |
normalizedAxis | Normalized rotation axis |
Expects that the rotation axis is normalized.
template<class T>
static Quaternion<T> Magnum:: Math:: Quaternion<T>:: fromMatrix(const Matrix3x3<T>& matrix)
Create quaternion from rotation matrix.
Expects that the matrix is orthogonal (i.e. pure rotation).
template<class T>
Magnum:: Math:: Quaternion<T>:: Quaternion(IdentityInitT = IdentityInit) constexpr noexcept
Default constructor.
Creates unit quaternion.
template<class T>
Magnum:: Math:: Quaternion<T>:: Quaternion(const Vector3<T>& vector,
T scalar) constexpr noexcept
Construct quaternion from vector and scalar.
template<class T>
Magnum:: Math:: Quaternion<T>:: Quaternion(const Vector3<T>& vector) explicit constexpr noexcept
Construct quaternion from vector.
To be used in transformations later.
template<class T>
template<class U>
Magnum:: Math:: Quaternion<T>:: Quaternion(const Quaternion<U>& other) explicit constexpr noexcept
Construct dual complex number from another of different type.
Performs only default casting on the values, no rounding or anything else.
template<class T>
bool Magnum:: Math:: Quaternion<T>:: isNormalized() const
Whether the quaternion is normalized.
Quaternion is normalized if it has unit length:
template<class T>
Quaternion<T>& Magnum:: Math:: Quaternion<T>:: operator+=(const Quaternion<T>& other)
Add and assign quaternion.
The computation is done in-place.
template<class T>
Quaternion<T> Magnum:: Math:: Quaternion<T>:: operator+(const Quaternion<T>& other) const
Add quaternion.
template<class T>
Quaternion<T> Magnum:: Math:: Quaternion<T>:: operator-() const
Negated quaternion.
template<class T>
Quaternion<T>& Magnum:: Math:: Quaternion<T>:: operator-=(const Quaternion<T>& other)
Subtract and assign quaternion.
The computation is done in-place.
template<class T>
Quaternion<T> Magnum:: Math:: Quaternion<T>:: operator-(const Quaternion<T>& other) const
Subtract quaternion.
template<class T>
Quaternion<T>& Magnum:: Math:: Quaternion<T>:: operator*=(T scalar)
Multiply with scalar and assign.
The computation is done in-place.
template<class T>
Quaternion<T> Magnum:: Math:: Quaternion<T>:: operator*(T scalar) const
Multiply with scalar.
template<class T>
Quaternion<T>& Magnum:: Math:: Quaternion<T>:: operator/=(T scalar)
Divide with scalar and assign.
The computation is done in-place.
template<class T>
Quaternion<T> Magnum:: Math:: Quaternion<T>:: operator/(T scalar) const
Divide with scalar.
template<class T>
Quaternion<T> Magnum:: Math:: Quaternion<T>:: operator*(const Quaternion<T>& other) const
Multiply with quaternion.
template<class T>
T Magnum:: Math:: Quaternion<T>:: length() const
Quaternion length.
See also dot() const which is faster for comparing length with other values.
template<class T>
Quaternion<T> Magnum:: Math:: Quaternion<T>:: normalized() const
Normalized quaternion (of unit length)
template<class T>
Quaternion<T> Magnum:: Math:: Quaternion<T>:: conjugated() const
Conjugated quaternion.
template<class T>
Quaternion<T> Magnum:: Math:: Quaternion<T>:: inverted() const
Inverted quaternion.
See invertedNormalized() which is faster for normalized quaternions.
template<class T>
Quaternion<T> Magnum:: Math:: Quaternion<T>:: invertedNormalized() const
Inverted normalized quaternion.
Equivalent to conjugated(). Expects that the quaternion is normalized.
template<class T>
Vector3<T> Magnum:: Math:: Quaternion<T>:: transformVector(const Vector3<T>& vector) const
Rotate vector with quaternion.
See transformVectorNormalized(), which is faster for normalized quaternions.
template<class T>
Vector3<T> Magnum:: Math:: Quaternion<T>:: transformVectorNormalized(const Vector3<T>& vector) const
Rotate vector with normalized quaternion.
Faster alternative to transformVector(), expects that the quaternion is normalized. Done using the following equation:
Which is equivalent to the common equation (source: https:/
template<class T>
template<class T>
T dot(const Quaternion<T>& a,
const Quaternion<T>& b)
Dot product between two quaternions.
template<class T>
template<class T>
Rad<T> angle(const Quaternion<T>& normalizedA,
const Quaternion<T>& normalizedB)
Angle between normalized quaternions.
Expects that both quaternions are normalized.
template<class T>
template<class T>
Quaternion<T> lerp(const Quaternion<T>& normalizedA,
const Quaternion<T>& normalizedB,
T t)
Linear interpolation of two quaternions.
Parameters | |
---|---|
normalizedA | First quaternion |
normalizedB | Second quaternion |
t | Interpolation phase (from range ) |
Expects that both quaternions are normalized.
template<class T>
template<class T>
Quaternion<T> slerp(const Quaternion<T>& normalizedA,
const Quaternion<T>& normalizedB,
T t)
Spherical linear interpolation of two quaternions.
Parameters | |
---|---|
normalizedA | First quaternion |
normalizedB | Second quaternion |
t | Interpolation phase (from range ) |
Expects that both quaternions are normalized. If the quaternions are the same or one is a negation of the other, returns the first argument.
template<class T>
template<class T>
Quaternion<T> operator*(T scalar,
const Quaternion<T>& quaternion)
Multiply scalar with quaternion.
Same as Quaternion::
template<class T>
template<class T>
Quaternion<T> operator/(T scalar,
const Quaternion<T>& quaternion)
Divide quaternion with number and invert.
template<class T>
template<class T>
Corrade:: Utility:: Debug& operator<<(Corrade:: Utility:: Debug& debug,
const Quaternion<T>& value)
Debug output operator.