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 constexprdeclval<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 constexprdeclval<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::
            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::
            Create quaternion from rotation matrix.
Expects that the matrix is orthogonal (i.e. pure rotation).
              
                template<class T>
              
               Magnum::
            Default constructor.
Creates unit quaternion.
              
                template<class T>
              
               Magnum::
            Construct quaternion from vector and scalar.
              
                template<class T>
              
               Magnum::
            Construct quaternion from vector.
To be used in transformations later.
              
                template<class T>
                template<class U>
              
               Magnum::
            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::
            Whether the quaternion is normalized.
Quaternion is normalized if it has unit length:
              
                template<class T>
              
              Quaternion<T>& Magnum::
            Add and assign quaternion.
The computation is done in-place.
              
                template<class T>
              
              Quaternion<T> Magnum::
            Add quaternion.
              
                template<class T>
              
              Quaternion<T> Magnum::
            Negated quaternion.
              
                template<class T>
              
              Quaternion<T>& Magnum::
            Subtract and assign quaternion.
The computation is done in-place.
              
                template<class T>
              
              Quaternion<T> Magnum::
            Subtract quaternion.
              
                template<class T>
              
              Quaternion<T>& Magnum::
            Multiply with scalar and assign.
The computation is done in-place.
              
                template<class T>
              
              Quaternion<T> Magnum::
            Multiply with scalar.
              
                template<class T>
              
              Quaternion<T>& Magnum::
            Divide with scalar and assign.
The computation is done in-place.
              
                template<class T>
              
              Quaternion<T> Magnum::
            Divide with scalar.
              
                template<class T>
              
              Quaternion<T> Magnum::
            Multiply with quaternion.
              
                template<class T>
              
              T Magnum::
            Quaternion length.
See also dot() const which is faster for comparing length with other values.
              
                template<class T>
              
              Quaternion<T> Magnum::
            Normalized quaternion (of unit length)
              
                template<class T>
              
              Quaternion<T> Magnum::
            Conjugated quaternion.
              
                template<class T>
              
              Quaternion<T> Magnum::
            Inverted quaternion.
See invertedNormalized() which is faster for normalized quaternions.
              
                template<class T>
              
              Quaternion<T> Magnum::
            Inverted normalized quaternion.
Equivalent to conjugated(). Expects that the quaternion is normalized.
              
                template<class T>
              
              Vector3<T> Magnum::
            Rotate vector with quaternion.
See transformVectorNormalized(), which is faster for normalized quaternions.
              
                template<class T>
              
              Vector3<T> Magnum::
            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::
            Debug output operator.