mal-math
C++20 mathematics library.
All Classes Namespaces Files Functions Variables Typedefs Concepts
quaternion.hpp File Reference

Quaternion operations and related mathematical functions. More...

#include "mat.hpp"
#include "quaternion.inl"
Include dependency graph for quaternion.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  mal_math::qua< T >
 Represents a quaternion with primitive type T. More...
 

Namespaces

namespace  mal_math
 Contains mathematical utility functions and classes.
 

Typedefs

using mal_math::quat = qua<float>
 
using mal_math::dquat = qua<double>
 

Functions

template<size_t size, Primitive T>
constexpr std::istream & mal_math::operator>> (std::istream &is, vec< size, T > &vec)
 Reads a vector of given size from an input stream.
 
template<size_t size, Primitive T>
constexpr std::ostream & mal_math::operator<< (std::ostream &os, vec< size, T > &vec)
 Writes a vector of given size to an output stream.
 
template<Primitive T, Primitive U>
constexpr qua< T > mal_math::operator* (U const value, qua< T > const &vector) noexcept
 Scalar-quaternion multiplication.
 
template<Primitive T, Primitive U>
constexpr qua< T > mal_math::operator/ (U const value, qua< T > const &vector) noexcept
 Scalar-quaternion division.
 
template<Primitive T, Primitive U>
constexpr qua< T > mal_math::operator* (qua< T > const &vector, U const value) noexcept
 Quaternion-scalar multiplication.
 
template<Primitive T, Primitive U>
constexpr qua< T > mal_math::operator/ (qua< T > const &vector, U const value) noexcept
 Quaternion-scalar division.
 
template<Primitive T, Primitive U>
constexpr qua< T > mal_math::operator+ (qua< T > const &left, qua< U > const &right) noexcept
 Quaternion addition.
 
template<Primitive T, Primitive U>
constexpr qua< T > mal_math::operator- (qua< T > const &left, qua< U > const &right) noexcept
 Quaternion subtraction.
 
template<Primitive T, Primitive U>
constexpr qua< T > mal_math::operator* (qua< T > const &left, qua< U > const &right) noexcept
 Quaternion multiplication.
 
template<Primitive T, Primitive U>
constexpr qua< T > mal_math::operator/ (qua< T > const &left, qua< U > const &right) noexcept
 Quaternion division.
 
template<Primitive T, Primitive U>
constexpr T mal_math::dot (qua< T > const &left, qua< U > const &right) noexcept
 Computes the dot product of two quaternions.
 
template<Primitive T>
constexpr T mal_math::angle (qua< T > const &quaternion) noexcept
 Computes the angle (or magnitude) of a quaternion.
 
template<Primitive T>
constexpr T mal_math::pitch (qua< T > const &quaternion) noexcept
 Computes the pitch from a quaternion.
 
template<Primitive T>
constexpr T mal_math::yaw (qua< T > const &quaternion) noexcept
 Computes the yaw from a quaternion.
 
template<Primitive T>
constexpr T mal_math::roll (qua< T > const &quaternion) noexcept
 Computes the roll from a quaternion.
 
template<Primitive T>
constexpr vec< 3, T > mal_math::QuaternionToEuler (qua< T > const &quaternion) noexcept
 Converts a quaternion to Euler angles.
 
template<Primitive T>
constexpr qua< T > mal_math::QuaternionFromEuler (vec< 3, T > const &angles) noexcept
 Creates a quaternion from Euler angles given in a vector.
 
template<Primitive T>
requires (std::is_floating_point_v<T>)
constexpr qua< T > mal_math::QuaternionFromEuler (T roll, T pitch, T yaw) noexcept
 Creates a quaternion from individual Euler angles.
 
template<AnyMat U>
requires (U::size.x == 3 && U::size.y == 3 && std::is_floating_point_v<typename U::type>)
constexpr qua< typename U::type > mal_math::QuaternionFromRotationMatrix (U const &mat) noexcept
 Creates a quaternion from a 3x3 rotation matrix.
 
template<Primitive T>
constexpr qua< T > mal_math::operator* (qua< T > const &q, qua< T > const &p) noexcept
 Quaternion-Quaternion multiplication.
 
template<Primitive T>
constexpr vec< 3, T > mal_math::operator* (qua< T > const &q, vec< 3, T > const &v) noexcept
 Quaternion-Vector multiplication.
 
template<Primitive T>
constexpr vec< 3, T > mal_math::operator* (vec< 3, T > const &v, qua< T > const &q) noexcept
 Vector-Quaternion multiplication.
 
template<Primitive T>
constexpr qua< T > mal_math::conjugate (qua< T > const &q) noexcept
 Computes the conjugate of a quaternion.
 
template<Primitive T>
constexpr qua< T > mal_math::inverse (qua< T > const &q) noexcept
 Computes the inverse of a quaternion.
 
template<Primitive T, Primitive U>
constexpr vec< 3, T > mal_math::cross (qua< T > const &left, vec< 3, U > const &right) noexcept
 Cross product between quaternion and vector.
 
template<Primitive T, Primitive U>
constexpr vec< 3, T > mal_math::cross (vec< 3, U > const &left, qua< T > const &right) noexcept
 Cross product between vector and quaternion.
 
template<Primitive T, Primitive U>
constexpr qua< T > mal_math::cross (qua< T > const &left, qua< U > const &right) noexcept
 Computes the cross product of two quaternions.
 
template<Primitive T>
constexpr mat< 4, 4, T > mal_math::rotate (mat< 4, 4, T > const &matrix, qua< T > const &q) noexcept
 Rotates a 4x4 matrix using a quaternion.
 
template<Primitive T>
constexpr T mal_math::length (qua< T > const &q) noexcept
 Computes the length (or magnitude) of a quaternion.
 
template<Primitive T>
constexpr qua< T > mal_math::normalize (qua< T > const &q) noexcept
 Normalizes a quaternion.
 

Detailed Description

Quaternion operations and related mathematical functions.

This header file provides the definition and utility functions for quaternions. Quaternions are mathematical objects used to represent rotations in 3D space without the gimbal lock issues that can be encountered with Euler angles. The file includes functions to convert between quaternions and various other forms of representing orientation and rotation, such as Euler angles and rotation matrices.

Definition in file quaternion.hpp.