Magnum::Math namespace

Math library.

Template classes for matrix and vector calculations.

This library is built as part of Magnum by default. To use this library with CMake, you need to find the Magnum package and link to the Magnum::Magnum target:

find_package(Magnum REQUIRED)

# ...
target_link_libraries(your-app Magnum::Magnum)

See Downloading and building, Usage with CMake, Operations with matrices and vectors and 2D and 3D transformations for more information.

Namespaces

namespace Algorithms
Algorithms.
namespace Distance
Functions for calculating distances.
namespace Geometry deprecated
namespace Intersection
Functions for calculating intersections.
namespace Literals
Math literals.

Classes

template<UnsignedInt order, UnsignedInt dimensions, class T>
class Bezier
Bézier curve.
template<std::size_t size>
class BoolVector
Vector storing boolean values.
template<class T>
class Color3
Color in linear RGB color space.
template<class T = Float>
class Color4
Color in linear RGBA color space.
template<class T>
struct ColorHsv
HSV color.
template<class T>
class Complex
Complex number.
template<class T>
struct Constants
Numeric constants.
template<class T>
class CubicHermite
Cubic Hermite spline point.
template<class T>
class Deg
Angle in degrees.
template<class T>
class Dual
Dual number.
template<class T>
class DualComplex
Dual complex number.
template<class T>
class DualQuaternion
Dual quaternion.
template<class T>
class Frustum
Camera frustum.
class Half
Half-precision float literal.
struct IdentityInitT
Identity initialization tag type.
template<class T>
struct IsFloatingPoint
Whether T is floating-point.
template<class T>
struct IsIntegral
Whether T is integral.
template<class T>
struct IsScalar
Whether T is an arithmetic scalar type.
template<class T>
struct IsUnitless
Whether T is a unitless tpye.
template<class T>
struct IsVector
Whether T is an arithmetic vector type.
template<std::size_t size, class T>
class Matrix
Square matrix.
template<class T>
class Matrix3
2D transformation matrix
template<class T>
class Matrix4
3D transformation matrix
template<class T>
class Quaternion
Quaternion.
template<class T>
class Rad
Angle in radians.
template<UnsignedInt dimensions, class T>
class Range
N-dimensional range.
template<class T>
class Range2D
Two-dimensional range.
template<class T>
class Range3D
Three-dimensional range.
template<std::size_t cols, std::size_t rows, class T>
class RectangularMatrix
Rectangular matrix.
struct StrictWeakOrdering
A functor which implements strict weak ordering.
template<class T>
struct TypeTraits
Traits class for builtin arithmetic types.
template<template<class> class Derived, class T>
class Unit
Base class for units.
template<std::size_t size, class T>
class Vector
Vector.
template<class T>
class Vector2
Two-component vector.
template<class T>
class Vector3
Three-component vector.
template<class T>
class Vector4
Four-component vector.
struct ZeroInitT
Zero initialization tag type.

Typedefs

template<UnsignedInt dimensions, class T>
using QuadraticBezier = Bezier<2, dimensions, T>
Quadratic Bézier curve.
template<class T>
using QuadraticBezier2D = QuadraticBezier<2, T>
Two-dimensional quadratic Bézier curve.
template<class T>
using QuadraticBezier3D = QuadraticBezier<3, T>
Three-dimensional quadratic Bézier curve.
template<UnsignedInt dimensions, class T>
using CubicBezier = Bezier<3, dimensions, T>
Cubic Bézier curve.
template<class T>
using CubicBezier2D = CubicBezier<2, T>
Two-dimensional cubic Bézier curve.
template<class T>
using CubicBezier3D = CubicBezier<3, T>
Three-dimensional cubic Bézier curve.
template<class T>
using CubicHermite1D = CubicHermite<T>
Scalar cubic Hermite spline point.
template<class T>
using CubicHermite2D = CubicHermite<Vector2<T>>
Two-dimensional cubic Hermite spline point.
template<class T>
using CubicHermite3D = CubicHermite<Vector3<T>>
Three-dimensional cubic Hermite spline point.
template<class T>
using CubicHermiteComplex = CubicHermite<Complex<T>>
Cubic Hermite spline complex number.
template<class T>
using CubicHermiteQuaternion = CubicHermite<Quaternion<T>>
Cubic Hermite spline quaternion.
template<class T>
using Matrix2x2 = Matrix<2, T>
2x2 matrix
template<class T>
using Matrix3x3 = Matrix<3, T>
3x3 matrix
template<class T>
using Matrix4x4 = Matrix<4, T>
4x4 matrix
template<class T>
using Range1D = Range<1, T>
One-dimensional range.
template<class T>
using Matrix2x3 = RectangularMatrix<2, 3, T>
Matrix with 2 columns and 3 rows.
template<class T>
using Matrix3x2 = RectangularMatrix<3, 2, T>
Matrix with 3 columns and 2 rows.
template<class T>
using Matrix2x4 = RectangularMatrix<2, 4, T>
Matrix with 2 columns and 4 rows.
template<class T>
using Matrix4x2 = RectangularMatrix<4, 2, T>
Matrix with 4 columns and 2 rows.
template<class T>
using Matrix3x4 = RectangularMatrix<3, 4, T>
Matrix with 3 columns and 4 rows.
template<class T>
using Matrix4x3 = RectangularMatrix<4, 3, T>
Matrix with 4 columns and 3 rows.
using NoInitT = Corrade::Containers::NoInitT
No initialization tag type.
template<class T>
using UnderlyingTypeOf = typename Implementation::UnderlyingType<T>::Type
Underlying builtin type for a scalar type.

Functions

template<class T>
auto operator<<(Corrade::Utility::Debug& debug, const Unit<Rad, T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<class T>
auto operator<<(Corrade::Utility::Debug& debug, const Unit<Deg, T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<UnsignedInt order, UnsignedInt dimensions, class T>
auto operator<<(Corrade::Utility::Debug& debug, const Bezier<order, dimensions, T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<std::size_t size>
auto operator<<(Corrade::Utility::Debug& debug, const BoolVector<size>& value) -> Corrade::Utility::Debug&
Debug output operator.
auto operator<<(Corrade::Utility::Debug& debug, const Color3<UnsignedByte>& value) -> Corrade::Utility::Debug&
Debug output operator.
auto operator<<(Corrade::Utility::Debug& debug, const Color4<UnsignedByte>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<class T>
auto xyYToXyz(const Vector3<T>& xyY) -> Vector3<T>
Convert color from CIE xyY representation to CIE XYZ.
template<class T>
auto xyzToXyY(const Vector3<T>& xyz) -> Vector3<T>
Convert color from CIE XYZ representation to CIE xyY.
template<class T>
auto operator<<(Corrade::Utility::Debug& debug, const ColorHsv<T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<class T>
auto dot(const Complex<T>& a, const Complex<T>& b) -> T
Dot product of two complex numbers.
template<class T>
auto angle(const Complex<T>& normalizedA, const Complex<T>& normalizedB) -> Rad<T>
Angle between normalized complex numbers.
template<class T>
auto operator*(const Vector2<T>& vector, const Complex<T>& complex) -> Complex<T>
Multiply a vector with a complex number.
template<class T>
auto lerp(const Complex<T>& normalizedA, const Complex<T>& normalizedB, T t) -> Complex<T>
Linear interpolation of two complex numbers.
template<class T>
auto slerp(const Complex<T>& normalizedA, const Complex<T>& normalizedB, T t) -> Complex<T>
Spherical linear interpolation of two complex numbers.
template<class T>
auto operator<<(Corrade::Utility::Debug& debug, const Complex<T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<class T>
auto operator<<(Corrade::Utility::Debug& debug, const CubicHermite<T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<class T, class U>
auto select(const CubicHermite<T>& a, const CubicHermite<T>& b, U t) -> T
Constant interpolation of two cubic Hermite spline points.
template<class T, class U>
auto lerp(const CubicHermite<T>& a, const CubicHermite<T>& b, U t) -> T
Linear interpolation of two cubic Hermite points.
template<class T>
auto lerp(const CubicHermiteComplex<T>& a, const CubicHermiteComplex<T>& b, T t) -> Complex<T>
Linear interpolation of two cubic Hermite complex numbers.
template<class T>
auto lerp(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t) -> Quaternion<T>
Linear interpolation of two cubic Hermite quaternions.
template<class T>
auto lerpShortestPath(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t) -> Quaternion<T>
Linear shortest-path interpolation of two cubic Hermite quaternions.
template<class T>
auto slerp(const CubicHermiteComplex<T>& a, const CubicHermiteComplex<T>& b, T t) -> Complex<T>
Spherical linear interpolation of two cubic Hermite complex numbers.
template<class T>
auto slerp(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t) -> Quaternion<T>
Spherical linear interpolation of two cubic Hermite quaternions.
template<class T>
auto slerpShortestPath(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t) -> Quaternion<T>
Spherical linear shortest-path interpolation of two cubic Hermite quaternions.
template<class T, class U>
auto splerp(const CubicHermite<T>& a, const CubicHermite<T>& b, U t) -> T
Spline interpolation of two cubic Hermite points.
template<class T>
auto splerp(const CubicHermiteComplex<T>& a, const CubicHermiteComplex<T>& b, T t) -> Complex<T>
Spline interpolation of two cubic Hermite complex numbers.
template<class T>
auto splerp(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t) -> Quaternion<T>
Spline interpolation of two cubic Hermite quaternions.
template<class T>
auto operator<<(Corrade::Utility::Debug& debug, const Dual<T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<class T>
auto sqrt(const Dual<T>& dual) -> Dual<T>
Square root of dual number.
template<class T>
auto sincos(const Dual<Rad<T>>& angle) -> std::pair<Dual<T>, Dual<T>>
Sine and cosine of dual angle.
template<class T>
auto operator<<(Corrade::Utility::Debug& debug, const DualComplex<T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<class T>
auto sclerp(const DualQuaternion<T>& normalizedA, const DualQuaternion<T>& normalizedB, const T t) -> DualQuaternion<T>
Screw linear interpolation of two dual quaternions.
template<class T>
auto sclerpShortestPath(const DualQuaternion<T>& normalizedA, const DualQuaternion<T>& normalizedB, const T t) -> DualQuaternion<T>
Screw linear shortest-path interpolation of two dual quaternions.
template<class T>
auto operator<<(Corrade::Utility::Debug& debug, const DualQuaternion<T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<class T>
auto operator<<(Corrade::Utility::Debug& debug, const Frustum<T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<class Integral>
auto div(Integral x, Integral y) -> std::pair<Integral, Integral>
Integer division with remainder.
auto operator<<(Corrade::Utility::Debug& debug, Half value) -> Corrade::Utility::Debug&
Debug output operator.
template<class T>
auto dot(const Quaternion<T>& a, const Quaternion<T>& b) -> T
Dot product between two quaternions.
template<class T>
auto angle(const Quaternion<T>& normalizedA, const Quaternion<T>& normalizedB) -> Rad<T>
Angle between normalized quaternions.
template<class T>
auto lerp(const Quaternion<T>& normalizedA, const Quaternion<T>& normalizedB, T t) -> Quaternion<T>
Linear interpolation of two quaternions.
template<class T>
auto lerpShortestPath(const Quaternion<T>& normalizedA, const Quaternion<T>& normalizedB, T t) -> Quaternion<T>
Linear shortest-path interpolation of two quaternions.
template<class T>
auto slerp(const Quaternion<T>& normalizedA, const Quaternion<T>& normalizedB, T t) -> Quaternion<T>
Spherical linear interpolation of two quaternions.
template<class T>
auto slerpShortestPath(const Quaternion<T>& normalizedA, const Quaternion<T>& normalizedB, T t) -> Quaternion<T>
Spherical linear shortest-path interpolation of two quaternions.
template<class T>
auto operator<<(Corrade::Utility::Debug& debug, const Quaternion<T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<UnsignedInt dimensions, class T>
auto join(const Range<dimensions, T>& a, const Range<dimensions, T>& b) -> Range<dimensions, T>
Join two ranges.
template<UnsignedInt dimensions, class T>
auto intersect(const Range<dimensions, T>& a, const Range<dimensions, T>& b) -> Range<dimensions, T>
Intersect two ranges.
template<UnsignedInt dimensions, class T>
auto intersects(const Range<dimensions, T>& a, const Range<dimensions, T>& b) -> bool
Whether two ranges intersect.
template<UnsignedInt dimensions, class T>
auto operator<<(Corrade::Utility::Debug& debug, const Range<dimensions, T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<std::size_t cols, std::size_t rows, class T>
auto operator<<(Corrade::Utility::Debug& debug, const Magnum::Math::RectangularMatrix<cols, rows, T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<char ... components, class T>
auto swizzle(const T& vector) -> Implementation::TypeForSize<sizeof...(components), T>::Type constexpr
Swizzle Vector components.
template<std::size_t size, class T>
auto dot(const Vector<size, T>& a, const Vector<size, T>& b) -> T
Dot product of two vectors.
template<std::size_t size, class FloatingPoint>
auto angle(const Vector<size, FloatingPoint>& normalizedA, const Vector<size, FloatingPoint>& normalizedB) -> Rad<FloatingPoint>
Angle between normalized vectors.
template<std::size_t size, class T>
auto operator<<(Corrade::Utility::Debug& debug, const Vector<size, T>& value) -> Corrade::Utility::Debug&
Debug output operator.
template<class T>
auto cross(const Vector2<T>& a, const Vector2<T>& b) -> T
2D cross product
template<class T>
auto cross(const Vector3<T>& a, const Vector3<T>& b) -> Vector3<T>
Cross product.
template<class T>
auto planeEquation(const Vector3<T>& p0, const Vector3<T>& p1, const Vector3<T>& p2) -> Vector4<T>
Create a plane equation from three points.
template<class T>
auto planeEquation(const Vector3<T>& normal, const Vector3<T>& point) -> Vector4<T>
Create a plane equation from a normal and a point.

Variables

NoInitT NoInit constexpr
No initialization tag.
ZeroInitT ZeroInit constexpr
Zero initialization tag.
IdentityInitT IdentityInit constexpr
Identity initialization tag.

Trigonometric functions

Unlike std::sin() and friends, those take or return strongly-typed units to prevent degrees being accidentally interpreted as radians and such. See Deg and Rad for more information.

template<class T>
auto sin(Rad<T> angle) -> T
Sine.
template<class T>
auto cos(Rad<T> angle) -> T
Cosine.
template<class T>
auto sincos(Rad<T> angle) -> std::pair<T, T>
Sine and cosine.
template<class T>
auto tan(Rad<T> angle) -> T
Tangent.
template<class T>
auto asin(T value) -> Rad<T>
Arc sine.
template<class T>
auto acos(T value) -> Rad<T>
Arc cosine.
template<class T>
auto atan(T value) -> Rad<T>
Arc tangent.

Scalar/vector functions

These functions are overloaded for both scalar and vector types, including Deg and Rad. Scalar versions function exactly as their possible STL equivalents, vector overloads perform the operations component-wise.

template<class T>
auto isInf(T value) -> std::enable_if<IsScalar<T>::value, bool>::type
If given number is a positive or negative infinity.
template<std::size_t size, class T>
auto isInf(const Vector<size, T>& value) -> BoolVector<size>
template<class T>
auto isNan(T value) -> std::enable_if<IsScalar<T>::value, bool>::type
If given number is a NaN.
template<std::size_t size, class T>
auto isNan(const Vector<size, T>& value) -> BoolVector<size>
template<class T>
auto min(T value, T min) -> std::enable_if<IsScalar<T>::value, T>::type constexpr
Minimum.
template<std::size_t size, class T>
auto min(const Vector<size, T>& value, const Vector<size, T>& min) -> Vector<size, T>
template<std::size_t size, class T>
auto min(const Vector<size, T>& value, T min) -> Vector<size, T>
template<class T>
auto max(T a, T b) -> std::enable_if<IsScalar<T>::value, T>::type constexpr
Maximum.
template<std::size_t size, class T>
auto max(const Vector<size, T>& value, const Vector<size, T>& max) -> Vector<size, T>
template<std::size_t size, class T>
auto max(const Vector<size, T>& value, T max) -> Vector<size, T>
template<class T>
auto minmax(T a, T b) -> std::enable_if<IsScalar<T>::value, std::pair<T, T>>::type
Minimum and maximum of two values.
template<std::size_t size, class T>
auto minmax(const Vector<size, T>& a, const Vector<size, T>& b) -> std::pair<Vector<size, T>, Vector<size, T>>
template<class T>
auto clamp(T value, T min, T max) -> std::enable_if<IsScalar<T>::value, T>::type
Clamp value.
template<std::size_t size, class T>
auto clamp(const Vector<size, T>& value, const Vector<size, T>& min, const Vector<size, T>& max) -> Vector<size, T>
template<std::size_t size, class T>
auto clamp(const Vector<size, T>& value, T min, T max) -> Vector<size, T>
template<class T>
auto sign(const T& scalar) -> std::enable_if<IsScalar<T>::value, T>::type
Sign.
template<std::size_t size, class T>
auto sign(const Vector<size, T>& a) -> Vector<size, T>
template<class T>
auto abs(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Absolute value.
template<std::size_t size, class T>
auto abs(const Vector<size, T>& a) -> Vector<size, T>
template<class T>
auto floor(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Nearest not larger integer.
template<std::size_t size, class T>
auto floor(const Vector<size, T>& a) -> Vector<size, T>
template<class T>
auto round(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Round value to nearest integer.
template<std::size_t size, class T>
auto round(const Vector<size, T>& a) -> Vector<size, T>
template<class T>
auto ceil(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Nearest not smaller integer.
template<std::size_t size, class T>
auto ceil(const Vector<size, T>& a) -> Vector<size, T>
template<class T, class U>
auto lerp(const T& a, const T& b, U t) -> T
Linear interpolation of two values.
template<class T>
auto lerp(const T& a, const T& b, bool t) -> T
template<std::size_t size, class T>
auto lerp(const Vector<size, T>& a, const Vector<size, T>& b, const BoolVector<size>& t) -> Vector<size, T>
template<std::size_t size>
auto lerp(const BoolVector<size>& a, const BoolVector<size>& b, const BoolVector<size>& t) -> BoolVector<size>
template<class T>
auto lerpInverted(T a, T b, T lerp) -> UnderlyingTypeOf<typename std::enable_if<IsScalar<T>::value, T>::type>
Inverse linear interpolation of two values.
template<std::size_t size, class T>
auto lerpInverted(const Vector<size, T>& a, const Vector<size, T>& b, const Vector<size, T>& lerp) -> Vector<size, UnderlyingTypeOf<T>>
template<class T, class U>
auto select(const T& a, const T& b, U t) -> T constexpr
Constant interpolation of two values.
template<class T>
auto fma(T a, T b, T c) -> std::enable_if<IsScalar<T>::value, T>::type
Fused multiply-add.
template<std::size_t size, class T>
auto fma(const Vector<size, T>& a, const Vector<size, T>& b, const Vector<size, T>& c) -> Vector<size, T>

Exponential and power functions

Unlike scalar/vector functions these don't work on Deg / Rad as the resulting unit can't be easily expressed.

auto log(UnsignedInt base, UnsignedInt number) -> UnsignedInt
Integral logarithm.
auto log2(UnsignedInt number) -> UnsignedInt
Base-2 integral logarithm.
template<class T>
auto log(T number) -> T
Natural logarithm.
template<class T>
auto exp(T exponent) -> T
Natural exponential.
template<UnsignedInt exponent, class T>
auto pow(T base) -> std::enable_if<IsScalar<T>::value, T>::type constexpr
Integral power.
template<UnsignedInt exponent, std::size_t size, class T>
auto pow(const Vector<size, T>& base) -> Vector<size, T>
template<class T>
auto pow(T base, T exponent) -> std::enable_if<IsScalar<T>::value, T>::type
Power.
template<std::size_t size, class T>
auto pow(const Vector<size, T>& base, T exponent) -> Vector<size, T>
template<class T>
auto sqrt(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Square root.
template<std::size_t size, class T>
auto sqrt(const Vector<size, T>& a) -> Vector<size, T>
template<class T>
auto sqrtInverted(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Inverse square root.
template<std::size_t size, class T>
auto sqrtInverted(const Vector<size, T>& a) -> Vector<size, T>

Batch functions

These functions process an ubounded range of values, as opposed to single vectors or scalars.

template<class T>
auto isInf(Corrade::Containers::StridedArrayView1D<const T> range) -> auto
If any number in the range is a positive or negative infinity.
template<class T>
auto isInf(std::initializer_list<T> list) -> auto
template<class T, std::size_t size>
auto isInf(const T(&array)[size]) -> auto
template<class T>
auto isNan(Corrade::Containers::StridedArrayView1D<const T> range) -> auto
If any number in the range is a NaN.
template<class T>
auto isNan(std::initializer_list<T> list) -> auto
template<class T, std::size_t size>
auto isNan(const T(&array)[size]) -> bool
template<class T>
auto min(Corrade::Containers::StridedArrayView1D<const T> range) -> T
Minimum of a range.
template<class T>
auto min(std::initializer_list<T> list) -> T
template<class T, std::size_t size>
auto min(const T(&array)[size]) -> T
template<class T>
auto max(Corrade::Containers::StridedArrayView1D<const T> range) -> T
Maximum of a range.
template<class T>
auto max(std::initializer_list<T> list) -> T
template<class T, std::size_t size>
auto max(const T(&array)[size]) -> T
template<class T>
auto minmax(Corrade::Containers::StridedArrayView1D<const T> range) -> std::pair<T, T>
Minimum and maximum of a range.
template<class T>
auto minmax(std::initializer_list<T> list) -> std::pair<T, T>
template<class T, std::size_t size>
auto minmax(const T(&array)[size]) -> std::pair<T, T>

Packing and unpacking functions

Similarly to scalar/vector functions these work on both scalars and vectors, including Deg and Rad.

auto unpackHalf(UnsignedShort value) -> Float
Unpack 16-bit half-float value into 32-bit float representation.
auto packHalf(Float value) -> UnsignedShort
Pack 32-bit float value into 16-bit half-float representation.
template<class FloatingPoint, class Integral>
auto unpack(const Integral& value) -> FloatingPoint
Unpack integral value into a floating-point representation.
template<class FloatingPoint, class Integral, UnsignedInt bits>
auto unpack(const Integral& value) -> FloatingPoint
Unpack integer bits into a floating-point representation.
template<class Integral, class FloatingPoint>
auto pack(const FloatingPoint& value) -> Integral
Pack floating-point value into an integer representation.
template<class Integral, UnsignedInt bits, class FloatingPoint>
auto pack(FloatingPoint value) -> Integral
Pack floating-point value into integer bits.
template<std::size_t size>
auto packHalf(const Vector<size, Float>& value) -> Vector<size, UnsignedShort>
template<std::size_t size>
auto unpackHalf(const Vector<size, UnsignedShort>& value) -> Vector<size, Float>

Typedef documentation

template<UnsignedInt dimensions, class T>
using Magnum::Math::QuadraticBezier = Bezier<2, dimensions, T>

Quadratic Bézier curve.

Convenience alternative to Bezier<2, dimensions, T>. See Bezier for more information.

template<class T>
using Magnum::Math::QuadraticBezier2D = QuadraticBezier<2, T>

Two-dimensional quadratic Bézier curve.

Convenience alternative to QuadraticBezier<2, T>. See QuadraticBezier and Bezier for more information.

template<class T>
using Magnum::Math::QuadraticBezier3D = QuadraticBezier<3, T>

Three-dimensional quadratic Bézier curve.

Convenience alternative to QuadraticBezier<3, T>. See QuadraticBezier and Bezier for more information.

template<UnsignedInt dimensions, class T>
using Magnum::Math::CubicBezier = Bezier<3, dimensions, T>

Cubic Bézier curve.

Convenience alternative to Bezier<3, dimensions, T>. See Bezier for more information.

template<class T>
using Magnum::Math::CubicBezier2D = CubicBezier<2, T>

Two-dimensional cubic Bézier curve.

Convenience alternative to CubicBezier<2, T>. See CubicBezier and Bezier for more information.

template<class T>
using Magnum::Math::CubicBezier3D = CubicBezier<3, T>

Three-dimensional cubic Bézier curve.

Convenience alternative to CubicBezier<3, T>. See CubicBezier and Bezier for more information.

template<class T>
using Magnum::Math::CubicHermite1D = CubicHermite<T>

Scalar cubic Hermite spline point.

Convenience alternative to CubicHermite<T>. See CubicHermite for more information.

template<class T>
using Magnum::Math::CubicHermite2D = CubicHermite<Vector2<T>>

Two-dimensional cubic Hermite spline point.

Convenience alternative to CubicHermite<Vector2<T>>. See CubicHermite for more information.

template<class T>
using Magnum::Math::CubicHermite3D = CubicHermite<Vector3<T>>

Three-dimensional cubic Hermite spline point.

Convenience alternative to CubicHermite<Vector2<T>>. See CubicHermite for more information.

template<class T>
using Magnum::Math::CubicHermiteComplex = CubicHermite<Complex<T>>

Cubic Hermite spline complex number.

Convenience alternative to CubicHermite<Complex<T>>. See CubicHermite for more information.

template<class T>
using Magnum::Math::CubicHermiteQuaternion = CubicHermite<Quaternion<T>>

Cubic Hermite spline quaternion.

Convenience alternative to CubicHermite<Quaternion<T>>. See CubicHermite for more information.

template<class T>
using Magnum::Math::Matrix2x2 = Matrix<2, T>

2x2 matrix

Convenience alternative to Matrix<2, T>. See Matrix for more information.

template<class T>
using Magnum::Math::Matrix3x3 = Matrix<3, T>

3x3 matrix

Convenience alternative to Matrix<3, T>. See Matrix for more information. Note that this is different from Matrix3, which contains additional functions for transformations in 2D.

template<class T>
using Magnum::Math::Matrix4x4 = Matrix<4, T>

4x4 matrix

Convenience alternative to Matrix<4, T>. See Matrix for more information. Note that this is different from Matrix4, which contains additional functions for transformations in 3D.

template<class T>
using Magnum::Math::Range1D = Range<1, T>

One-dimensional range.

Convenience alternative to Range<1, T>. See Range for more information.

template<class T>
using Magnum::Math::Matrix2x3 = RectangularMatrix<2, 3, T>

Matrix with 2 columns and 3 rows.

Convenience alternative to RectangularMatrix<2, 3, T>. See RectangularMatrix for more information.

template<class T>
using Magnum::Math::Matrix3x2 = RectangularMatrix<3, 2, T>

Matrix with 3 columns and 2 rows.

Convenience alternative to RectangularMatrix<3, 2, T>. See RectangularMatrix for more information.

template<class T>
using Magnum::Math::Matrix2x4 = RectangularMatrix<2, 4, T>

Matrix with 2 columns and 4 rows.

Convenience alternative to RectangularMatrix<2, 4, T>. See RectangularMatrix for more information.

template<class T>
using Magnum::Math::Matrix4x2 = RectangularMatrix<4, 2, T>

Matrix with 4 columns and 2 rows.

Convenience alternative to RectangularMatrix<4, 2, T>. See RectangularMatrix for more information.

template<class T>
using Magnum::Math::Matrix3x4 = RectangularMatrix<3, 4, T>

Matrix with 3 columns and 4 rows.

Convenience alternative to RectangularMatrix<3, 4, T>. See RectangularMatrix for more information.

template<class T>
using Magnum::Math::Matrix4x3 = RectangularMatrix<4, 3, T>

Matrix with 4 columns and 3 rows.

Convenience alternative to RectangularMatrix<4, 3, T>. See RectangularMatrix for more information.

typedef Corrade::Containers::NoInitT Magnum::Math::NoInitT

No initialization tag type.

Used to distinguish construction with no initialization at all.

template<class T>
using Magnum::Math::UnderlyingTypeOf = typename Implementation::UnderlyingType<T>::Type

Underlying builtin type for a scalar type.

For builtin types returns the type itself, for wrapped types like Deg or Rad returns the underlying builtin type. It's guaranteed that the input type is always explicitly convertible to the output type and the output type is usable with standard APIs such as std::isinf().

Passed types are required to satisfy IsScalar. All non-scalar Magnum math types have a member typedef Type containing the underlying type.

Function documentation

template<class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const Unit<Rad, T>& value)

Debug output operator.

template<class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const Unit<Deg, T>& value)

Debug output operator.

template<UnsignedInt order, UnsignedInt dimensions, class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const Bezier<order, dimensions, T>& value)

Debug output operator.

template<std::size_t size>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const BoolVector<size>& value)

Debug output operator.

In order to avoid potential confusion, prints the value as a comma-separated sequence of binary literals, so the output corresponds to how the value would be constructed. For example,

Debug{} << BoolVector4{0b1010}
        << Math::BoolVector<19>{0b00001000, 0b00000011, 0b100};

prints as

BoolVector(0b1010) BoolVector(0b00001000, 0b00000011, 0b100)

Note that this, on the other hand, makes mapping to bit indices less obvious — see Bit indexing for more information.

Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const Color3<UnsignedByte>& value)

Debug output operator.

If Corrade::Utility::Debug::Flag::Color is enabled or Corrade::Utility::Debug::color was set immediately before, prints the value as an ANSI 24bit color escape sequence using two successive Unicode block characters (to have it roughly square). To preserve at least some information when text is copied, the square consists of one of the five ░▒▓█ shades, however the color is set for both foreground and background so the actual block character is indistinguishable when seen on a terminal.

If Corrade::Utility::Debug::Flag::Color is enabled and Corrade::Utility::Debug::Flag::DisableColors is set, only the shaded character is used, without any ANSI color escape sequence.

If Corrade::Utility::Debug::Flag::Color is not enabled, the value is printed as a hex color (e.g. #ff33aa). Other underlying types are handled by operator<<(Corrade::Utility::Debug&, const Vector<size, T>&).

For example, the following snippet:

Debug{Debug::Flag::Color} << 0xdcdcdc_rgb << 0xa5c9ea_rgb << 0x3bd267_rgb
    << 0xc7cf2f_rgb << 0xcd3431_rgb << 0x2f83cc_rgb << 0x747474_rgb;

prints the following on terminals that support it:

‌██ ‌██ ‌██ ‌██ ‌██ ‌▓▓ ‌▒▒

Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const Color4<UnsignedByte>& value)

Debug output operator.

If Corrade::Utility::Debug::Flag::Color is enabled or Corrade::Utility::Debug::color was set immediately before, prints the value as an ANSI 24bit color escape sequence using two successive Unicode block characters (to have it roughly square). To preserve at least some information when text is copied, the square consists of one of the five ░▒▓█ shades. The square shade is calculated as a product of Color4::value() and Color4::a(). If calculated color value is less than alpha, the colored square has the color set for both background and foreground, otherwise the background is left at the default.

If Corrade::Utility::Debug::Flag::Color is enabled and Corrade::Utility::Debug::Flag::DisableColors is set, only the shaded character is used, without any ANSI color escape sequence.

If Corrade::Utility::Debug::Flag::Color is not enabled, the value is printed as a hex color (e.g. #ff33aaff). Other underlying types are handled by operator<<(Corrade::Utility::Debug&, const Vector<size, T>&).

For example, the following snippet:

Debug{Debug::Flag::Color}
    << 0x3bd26700_rgba << 0x3bd26733_rgba << 0x3bd26766_rgba
    << 0x3bd26799_rgba << 0x3bd267cc_rgba << 0x3bd267ff_rgba;

prints the following on terminals that support it:

  ‌░░ ‌▒▒ ‌▓▓ ‌██

template<class T>
Vector3<T> Magnum::Math::xyYToXyz(const Vector3<T>& xyY)

Convert color from CIE xyY representation to CIE XYZ.

\[ \begin{array}{rcl} X & = & \dfrac{Y}{y}x \\ Z & = & \dfrac{Y}{y}(1 - x - y) \end{array} \]

template<class T>
Vector3<T> Magnum::Math::xyzToXyY(const Vector3<T>& xyz)

Convert color from CIE XYZ representation to CIE xyY.

\[ \begin{array}{rcl} x & = & \dfrac{X}{X + Y + Z} \\ y & = & \dfrac{Y}{X + Y + Z} \end{array} \]

template<class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const ColorHsv<T>& value)

Debug output operator.

template<class T>
T Magnum::Math::dot(const Complex<T>& a, const Complex<T>& b)

Dot product of two complex numbers.

\[ c_0 \cdot c_1 = a_0 a_1 + b_0 b_1 \]

template<class T>
Rad<T> Magnum::Math::angle(const Complex<T>& normalizedA, const Complex<T>& normalizedB)

Angle between normalized complex numbers.

Expects that both complex numbers are normalized.

\[ \theta = \arccos \left( \frac{Re(c_0 \cdot c_1))}{|c_0| |c_1|} \right) = \arccos (a_0 a_1 + b_0 b_1) \]

template<class T>
Complex<T> Magnum::Math::operator*(const Vector2<T>& vector, const Complex<T>& complex)

Multiply a vector with a complex number.

Same as Complex::operator*(const Vector2<T>&) const.

template<class T>
Complex<T> Magnum::Math::lerp(const Complex<T>& normalizedA, const Complex<T>& normalizedB, T t)

Linear interpolation of two complex numbers.

Parameters
normalizedA First complex number
normalizedB Second complex number
t Interpolation phase (from range $ [0; 1] $ )

Expects that both complex numbers are normalized.

\[ c_{LERP} = \frac{(1 - t) c_A + t c_B}{|(1 - t) c_A + t c_B|} \]

template<class T>
Complex<T> Magnum::Math::slerp(const Complex<T>& normalizedA, const Complex<T>& normalizedB, T t)

Spherical linear interpolation of two complex numbers.

Parameters
normalizedA First complex number
normalizedB Second complex number
t Interpolation phase (from range $ [0; 1] $ )

Expects that both complex numbers are normalized. If the complex numbers are the same, returns the first argument.

\[ \begin{array}{rcl} \theta & = & \arccos \left( \frac{c_A \cdot c_B}{|c_A| |c_B|} \right) = \arccos(c_A \cdot c_B) \\[6pt] c_{SLERP} & = & \cfrac{\sin((1 - t) \theta) c_A + \sin(t \theta) c_B}{\sin(\theta)} \end{array} \]

template<class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const Complex<T>& value)

Debug output operator.

template<class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const CubicHermite<T>& value)

Debug output operator.

template<class T, class U>
T Magnum::Math::select(const CubicHermite<T>& a, const CubicHermite<T>& b, U t)

Constant interpolation of two cubic Hermite spline points.

Parameters
a First spline point
b Second spline point
t Interpolation phase (from range $ [0; 1] $ )

Given segment points $ \boldsymbol{p}_i $ , in-tangents $ \boldsymbol{m}_i $ and out-tangents $ \boldsymbol{n}_i $ , the interpolated value $ \boldsymbol{p} $ at phase $ t $ is:

\[ \boldsymbol{p}(t) = \begin{cases} \boldsymbol{p}_a, & t < 1 \\ \boldsymbol{p}_b, & t \ge 1 \end{cases} \]

Equivalent to calling select(const T&, const T&, U) on CubicHermite::point() extracted from both a and b.

template<class T, class U>
T Magnum::Math::lerp(const CubicHermite<T>& a, const CubicHermite<T>& b, U t)

Linear interpolation of two cubic Hermite points.

Parameters
a First spline point
b Second spline point
t Interpolation phase (from range $ [0; 1] $ )

Given segment points $ \boldsymbol{p}_i $ , in-tangents $ \boldsymbol{m}_i $ and out-tangents $ \boldsymbol{n}_i $ , the interpolated value $ \boldsymbol{p} $ at phase $ t $ is:

\[ \boldsymbol{p}(t) = (1 - t) \boldsymbol{p}_a + t \boldsymbol{p}_b \]

Equivalent to calling lerp(const T&, const T&, U) on CubicHermite::point() extracted from both a and b.

template<class T>
Complex<T> Magnum::Math::lerp(const CubicHermiteComplex<T>& a, const CubicHermiteComplex<T>& b, T t)

Linear interpolation of two cubic Hermite complex numbers.

Equivalent to calling lerp(const Complex<T>&, const Complex<T>&, T) on CubicHermite::point() extracted from a and b. Compared to lerp(const CubicHermite<T>&, const CubicHermite<T>&, U) this adds a normalization step after. Expects that CubicHermite::point() is a normalized complex number in both a and b.

template<class T>
Quaternion<T> Magnum::Math::lerp(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t)

Linear interpolation of two cubic Hermite quaternions.

Equivalent to calling lerp(const Quaternion<T>&, const Quaternion<T>&, T) on CubicHermite::point() extracted from a and b. Compared to lerp(const CubicHermite<T>&, const CubicHermite<T>&, U) this adds a normalization step after. Expects that CubicHermite::point() is a normalized quaternion in both a and b.

template<class T>
Quaternion<T> Magnum::Math::lerpShortestPath(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t)

Linear shortest-path interpolation of two cubic Hermite quaternions.

Equivalent to calling lerpShortestPath(const Quaternion<T>&, const Quaternion<T>&, T) on CubicHermite::point() extracted from a and b. Expects that CubicHermite::point() is a normalized quaternion in both a and b.

Note that rotations interpolated with this function may go along a completely different path compared to splerp(const CubicHermiteQuaternion<T>&, const CubicHermiteQuaternion<T>&, T). Use lerp(const CubicHermiteQuaternion<T>&, const CubicHermiteQuaternion<T>&, T) for behavior that is consistent with spline interpolation.

template<class T>
Quaternion<T> Magnum::Math::slerp(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t)

Spherical linear interpolation of two cubic Hermite quaternions.

Equivalent to calling slerp(const Quaternion<T>&, const Quaternion<T>&, T) on CubicHermite::point() extracted from a and b. Expects that CubicHermite::point() is a normalized complex number in both a and b.

template<class T>
Quaternion<T> Magnum::Math::slerpShortestPath(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t)

Spherical linear shortest-path interpolation of two cubic Hermite quaternions.

Equivalent to calling slerpShortestPath(const Quaternion<T>&, const Quaternion<T>&, T) on CubicHermite::point() extracted from a and b. Expects that CubicHermite::point() is a normalized quaternion in both a and b.

Note that rotations interpolated with this function may go along a completely different path compared to splerp(const CubicHermiteQuaternion<T>&, const CubicHermiteQuaternion<T>&, T). Use slerp(const CubicHermiteQuaternion<T>&, const CubicHermiteQuaternion<T>&, T) for spherical linear interpolation with behavior that is consistent with spline interpolation.

template<class T, class U>
T Magnum::Math::splerp(const CubicHermite<T>& a, const CubicHermite<T>& b, U t)

Spline interpolation of two cubic Hermite points.

Parameters
a First spline point
b Second spline point
t Interpolation phase

Given segment points $ \boldsymbol{p}_i $ , in-tangents $ \boldsymbol{m}_i $ and out-tangents $ \boldsymbol{n}_i $ , the interpolated value $ \boldsymbol{p} $ at phase $ t $ is:

\[ \boldsymbol{p}(t) = (2 t^3 - 3 t^2 + 1) \boldsymbol{p}_a + (t^3 - 2 t^2 + t) \boldsymbol{n}_a + (-2 t^3 + 3 t^2) \boldsymbol{p}_b + (t^3 - t^2)\boldsymbol{m}_b \]

template<class T>
Complex<T> Magnum::Math::splerp(const CubicHermiteComplex<T>& a, const CubicHermiteComplex<T>& b, T t)

Spline interpolation of two cubic Hermite complex numbers.

Unlike splerp(const CubicHermite<T>&, const CubicHermite<T>&, U) this adds a normalization step after. Given segment points $ \boldsymbol{p}_i $ , in-tangents $ \boldsymbol{m}_i $ and out-tangents $ \boldsymbol{n}_i $ , the interpolated value $ \boldsymbol{p} $ at phase $ t $ is:

\[ \begin{array}{rcl} \boldsymbol{p'}(t) & = & (2 t^3 - 3 t^2 + 1) \boldsymbol{p}_a + (t^3 - 2 t^2 + t) \boldsymbol{n}_a + (-2 t^3 + 3 t^2) \boldsymbol{p}_b + (t^3 - t^2)\boldsymbol{m}_b \\ \boldsymbol{p}(t) & = & \cfrac{\boldsymbol{p'}(t)}{|\boldsymbol{p'}(t)|} \end{array} \]

Expects that CubicHermite::point() is a normalized complex number in both a and b.

template<class T>
Quaternion<T> Magnum::Math::splerp(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t)

Spline interpolation of two cubic Hermite quaternions.

Unlike splerp(const CubicHermite<T>&, const CubicHermite<T>&, U) this adds a normalization step after. Given segment points $ \boldsymbol{p}_i $ , in-tangents $ \boldsymbol{m}_i $ and out-tangents $ \boldsymbol{n}_i $ , the interpolated value $ \boldsymbol{p} $ at phase $ t $ is:

\[ \begin{array}{rcl} \boldsymbol{p'}(t) & = & (2 t^3 - 3 t^2 + 1) \boldsymbol{p}_a + (t^3 - 2 t^2 + t) \boldsymbol{n}_a + (-2 t^3 + 3 t^2) \boldsymbol{p}_b + (t^3 - t^2)\boldsymbol{m}_b \\ \boldsymbol{p}(t) & = & \cfrac{\boldsymbol{p'}(t)}{|\boldsymbol{p'}(t)|} \end{array} \]

Expects that CubicHermite::point() is a normalized quaternion in both a and b.

template<class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const Dual<T>& value)

Debug output operator.

template<class T>
Dual<T> Magnum::Math::sqrt(const Dual<T>& dual)

Square root of dual number.

\[ \sqrt{\hat a} = \sqrt{a_0} + \epsilon \frac{a_\epsilon}{2 \sqrt{a_0}} \]

template<class T>
std::pair<Dual<T>, Dual<T>> Magnum::Math::sincos(const Dual<Rad<T>>& angle)

Sine and cosine of dual angle.

\[ \begin{array}{rcl} sin(\hat a) & = & sin(a_0) + \epsilon a_\epsilon cos(a_0) \\ cos(\hat a) & = & cos(a_0) - \epsilon a_\epsilon sin(a_0) \end{array} \]

template<class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const DualComplex<T>& value)

Debug output operator.

template<class T>
DualQuaternion<T> Magnum::Math::sclerp(const DualQuaternion<T>& normalizedA, const DualQuaternion<T>& normalizedB, const T t)

Screw linear interpolation of two dual quaternions.

Parameters
normalizedA First dual quaternion
normalizedB Second dual quaternion
t Interpolation phase (from range $ [0; 1] $ )

Expects that both dual quaternions are normalized. If the real parts are the same or one is a negation of the other, returns the DualQuaternion::rotation() (real) part combined with interpolated DualQuaternion::translation():

\[ \begin{array}{rcl} d & = & q_{A_0} \cdot q_{B_0} \\[5pt] {\hat q}_{ScLERP} & = & 2 \left[(1 - t)(q_{A_\epsilon} q_{A_0}^*)_V + t (q_{B_\epsilon} q_{B_0}^*)_V \right] q_A, ~ {\color{m-primary} \text{if} ~ d \ge 1} \end{array} \]

otherwise, the interpolation is performed as:

\[ \begin{array}{rcl} l + \epsilon m & = & \hat q_A^* \hat q_B \\[5pt] \frac{\hat a} 2 & = & \arccos \left( l_S \right) - \epsilon m_S \frac 1 {|\boldsymbol{l}_V|} \\[5pt] \hat {\boldsymbol n} & = & \boldsymbol n_0 + \epsilon \boldsymbol n_\epsilon, ~~~~~~~~ \boldsymbol n_0 = \boldsymbol{l}_V \frac 1 {|\boldsymbol{l}_V|}, ~~~~~~~~ \boldsymbol n_\epsilon = \left(\boldsymbol{m}_V - {\boldsymbol n}_0 \frac {a_\epsilon} 2 l_S \right)\frac 1 {|\boldsymbol{l}_V|} \\[5pt] {\hat q}_{ScLERP} & = & \hat q_A (\hat q_A^* \hat q_B)^t = \hat q_A \left[ \hat {\boldsymbol n} \sin \left( t \frac {\hat a} 2 \right), \cos \left( t \frac {\hat a} 2 \right) \right] \end{array} \]

Note that this function does not check for shortest path interpolation, see sclerpShortestPath() for an alternative.

template<class T>
DualQuaternion<T> Magnum::Math::sclerpShortestPath(const DualQuaternion<T>& normalizedA, const DualQuaternion<T>& normalizedB, const T t)

Screw linear shortest-path interpolation of two dual quaternions.

Parameters
normalizedA First dual quaternion
normalizedB Second dual quaternion
t Interpolation phase (from range $ [0; 1] $ )

Unlike sclerp(const DualQuaternion<T>&, const DualQuaternion<T>&, T) this function interpolates on the shortest path. Expects that both dual quaternions are normalized. If the real parts are the same or one is a negation of the other, returns the DualQuaternion::rotation() (real) part combined with interpolated DualQuaternion::translation():

\[ \begin{array}{rcl} d & = & q_{A_0} \cdot q_{B_0} \\[5pt] {\hat q}_{ScLERP} & = & 2 \left((1 - t)(q_{A_\epsilon} q_{A_0}^*)_V + t (q_{B_\epsilon} q_{B_0}^*)_V \right) (q_{A_0} + \epsilon [\boldsymbol{0}, 0]), ~ {\color{m-primary} \text{if} ~ d \ge 1} \end{array} \]

otherwise, the interpolation is performed as:

\[ \begin{array}{rcl} l + \epsilon m & = & \begin{cases} \phantom{-}\hat q_A^* \hat q_B, & d \ge 0 \\ -\hat q_A^* \hat q_B, & d < 0 \\ \end{cases} \\[15pt] \frac{\hat a} 2 & = & \arccos \left( l_S \right) - \epsilon m_S \frac 1 {|\boldsymbol{l}_V|} \\[5pt] \hat {\boldsymbol n} & = & \boldsymbol n_0 + \epsilon \boldsymbol n_\epsilon, ~~~~~~~~ \boldsymbol n_0 = \boldsymbol{l}_V \frac 1 {|\boldsymbol{l}_V|}, ~~~~~~~~ \boldsymbol n_\epsilon = \left(\boldsymbol{m}_V - {\boldsymbol n}_0 \frac {a_\epsilon} 2 l_S \right)\frac 1 {|\boldsymbol{l}_V|} \\[5pt] {\hat q}_{ScLERP} & = & \hat q_A (\hat q_A^* \hat q_B)^t = \hat q_A \left[ \hat {\boldsymbol n} \sin \left( t \frac {\hat a} 2 \right), \cos \left( t \frac {\hat a} 2 \right) \right] \end{array} \]

template<class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const DualQuaternion<T>& value)

Debug output operator.

template<class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const Frustum<T>& value)

Debug output operator.

template<class Integral>
std::pair<Integral, Integral> Magnum::Math::div(Integral x, Integral y)

Integer division with remainder.

Example usage:

Int quotient, remainder;
std::tie(quotient, remainder) = Math::div(57, 6); // {9, 3}

Equivalent to the following, but possibly done in a single CPU instruction:

Int quotient = 57/6;
Int remainder = 57%6;

template<class T>
T Magnum::Math::dot(const Quaternion<T>& a, const Quaternion<T>& b)

Dot product between two quaternions.

\[ p \cdot q = \boldsymbol p_V \cdot \boldsymbol q_V + p_S q_S \]

template<class T>
Rad<T> Magnum::Math::angle(const Quaternion<T>& normalizedA, const Quaternion<T>& normalizedB)

Angle between normalized quaternions.

Expects that both quaternions are normalized.

\[ \theta = \arccos \left( \frac{p \cdot q}{|p| |q|} \right) = \arccos(p \cdot q) \]

template<class T>
Quaternion<T> Magnum::Math::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 $ [0; 1] $ )

Expects that both quaternions are normalized.

\[ q_{LERP} = \frac{(1 - t) q_A + t q_B}{|(1 - t) q_A + t q_B|} \]

Note that this function does not check for shortest path interpolation, see lerpShortestPath(const Quaternion<T>&, const Quaternion<T>&, T) for an alternative.

template<class T>
Quaternion<T> Magnum::Math::lerpShortestPath(const Quaternion<T>& normalizedA, const Quaternion<T>& normalizedB, T t)

Linear shortest-path interpolation of two quaternions.

Parameters
normalizedA First quaternion
normalizedB Second quaternion
t Interpolation phase (from range $ [0; 1] $ )

Unlike lerp(const Quaternion<T>&, const Quaternion<T>&, T), this interpolates on the shortest path at some performance expense. Expects that both quaternions are normalized.

\[ \begin{array}{rcl} d & = & q_A \cdot q_B \\[5pt] q'_A & = & \begin{cases} \phantom{-}q_A, & d \ge 0 \\ -q_A, & d < 0 \end{cases} \\[15pt] q_{LERP} & = & \cfrac{(1 - t) q'_A + t q_B}{|(1 - t) q'_A + t q_B|} \end{array} \]

template<class T>
Quaternion<T> Magnum::Math::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 $ [0; 1] $ )

Expects that both quaternions are normalized. If the quaternions are the same or one is a negation of the other, it just returns the first argument:

\[ \begin{array}{rcl} d & = & q_A \cdot q_B \\[5pt] q_{SLERP} & = & q_A, ~ {\color{m-primary} \text{if} ~ d \ge 1} \end{array} \]

otherwise, the interpolation is performed as:

\[ \begin{array}{rcl} \theta & = & \arccos \left( \frac{q_A \cdot q_B}{|q_A| |q_B|} \right) = \arccos(q_A \cdot q_B) = \arccos(d) \\[5pt] q_{SLERP} & = & \cfrac{\sin((1 - t) \theta) q_A + \sin(t \theta) q_B}{\sin(\theta)} \end{array} \]

Note that this function does not check for shortest path interpolation, see slerpShortestPath(const Quaternion<T>&, const Quaternion<T>&, T) for an alternative.

template<class T>
Quaternion<T> Magnum::Math::slerpShortestPath(const Quaternion<T>& normalizedA, const Quaternion<T>& normalizedB, T t)

Spherical linear shortest-path interpolation of two quaternions.

Parameters
normalizedA First quaternion
normalizedB Second quaternion
t Interpolation phase (from range $ [0; 1] $ )

Unlike slerp(const Quaternion<T>&, const Quaternion<T>&, T) this function interpolates on the shortest path. Expects that both quaternions are normalized. If the quaternions are the same or one is a negation of the other, it just returns the first argument:

\[ \begin{array}{rcl} d & = & q_A \cdot q_B \\ q_{SLERP} & = & q_A, ~ {\color{m-primary} \text{if} ~ d \ge 1} \end{array} \]

otherwise, the interpolation is performed as:

\[ \begin{array}{rcl} q'_A & = & \begin{cases} \phantom{-}q_A, & d \ge 0 \\ -q_A, & d < 0 \end{cases} \\[15pt] \theta & = & \arccos \left( \frac{|q'_A \cdot q_B|}{|q'_A| |q_B|} \right) = \arccos(|q'_A \cdot q_B|) = \arccos(|d|) \\[5pt] q_{SLERP} & = & \cfrac{\sin((1 - t) \theta) q'_A + \sin(t \theta) q_B}{\sin(\theta)} \end{array} \]

template<class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const Quaternion<T>& value)

Debug output operator.

template<UnsignedInt dimensions, class T>
Range<dimensions, T> Magnum::Math::join(const Range<dimensions, T>& a, const Range<dimensions, T>& b)

Join two ranges.

Returns a range that contains both input ranges. If one of the ranges is empty, only the other is returned. Results are undefined if any range has a negative size.

template<UnsignedInt dimensions, class T>
Range<dimensions, T> Magnum::Math::intersect(const Range<dimensions, T>& a, const Range<dimensions, T>& b)

Intersect two ranges.

Returns a range that covers the intersection of both ranges. If the intersection is empty, a default-constructed range is returned. The range minimum is interpreted as inclusive, maximum as exclusive. Results are undefined if any range has a negative size.

template<UnsignedInt dimensions, class T>
bool Magnum::Math::intersects(const Range<dimensions, T>& a, const Range<dimensions, T>& b)

Whether two ranges intersect.

Returns true if the following holds for all dimensions $ i $ , false otherwise.

\[ \bigwedge_i (\operatorname{max}(A)_i > \operatorname{min}(B)_i) \land (\operatorname{min}(A)_i < \operatorname{max}(B)_i) \]

The range minimum is interpreted as inclusive, maximum as exclusive. Results are undefined if any range has a negative size.

template<UnsignedInt dimensions, class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const Range<dimensions, T>& value)

Debug output operator.

template<std::size_t cols, std::size_t rows, class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const Magnum::Math::RectangularMatrix<cols, rows, T>& value)

Debug output operator.

template<char ... components, class T>
Implementation::TypeForSize<sizeof...(components), T>::Type Magnum::Math::swizzle(const T& vector) constexpr

Swizzle Vector components.

Creates new vector from given components. Example:

Vector4i original(-1, 2, 3, 4);

auto vec = Math::swizzle<'w', '1', '0', 'x', 'y', 'z'>(original);
        // vec == { 4, 1, 0, -1, 2, 3 }

You can use letters 'x', 'y', 'z', 'w' and 'r', 'g', 'b', 'a' for addressing components or letters '0' and '1' for zero and one. Count of elements is unlimited, but must be at least one. If the resulting vector is two, three or four-component, corresponding Vector2, Vector3, Vector4, Color3 or Color4 specialization is returned.

template<std::size_t size, class T>
T Magnum::Math::dot(const Vector<size, T>& a, const Vector<size, T>& b)

Dot product of two vectors.

Returns 0 when two vectors are perpendicular, > 0 when two vectors are in the same general direction, 1 when two normalized vectors are parallel, < 0 when two vectors are in opposite general direction and -1 when two normalized vectors are antiparallel.

\[ \boldsymbol a \cdot \boldsymbol b = \sum_{i=0}^{n-1} \boldsymbol a_i \boldsymbol b_i \]

template<std::size_t size, class FloatingPoint>
Rad<FloatingPoint> Magnum::Math::angle(const Vector<size, FloatingPoint>& normalizedA, const Vector<size, FloatingPoint>& normalizedB)

Angle between normalized vectors.

Expects that both vectors are normalized. Enabled only for floating-point types.

\[ \theta = \arccos \left( \frac{\boldsymbol a \cdot \boldsymbol b}{|\boldsymbol a| |\boldsymbol b|} \right) = \arccos (\boldsymbol a \cdot \boldsymbol b) \]

template<std::size_t size, class T>
Corrade::Utility::Debug& Magnum::Math::operator<<(Corrade::Utility::Debug& debug, const Vector<size, T>& value)

Debug output operator.

template<class T>
T Magnum::Math::cross(const Vector2<T>& a, const Vector2<T>& b)

2D cross product

2D version of cross product, also called perp-dot product, equivalent to calling cross(const Vector3<T>&, const Vector3<T>&) with Z coordinate set to 0 and extracting only Z coordinate from the result (X and Y coordinates are always zero). Returns 0 either when one of the vectors is zero or they are parallel or antiparallel and 1 when two normalized vectors are perpendicular.

\[ \boldsymbol a \times \boldsymbol b = \boldsymbol a_\bot \cdot \boldsymbol b = a_xb_y - a_yb_x \]

template<class T>
Vector3<T> Magnum::Math::cross(const Vector3<T>& a, const Vector3<T>& b)

Cross product.

Result has length of 0 either when one of them is zero or they are parallel or antiparallel and length of 1 when two normalized vectors are perpendicular. Done using the following equation:

\[ \boldsymbol a \times \boldsymbol b = \begin{pmatrix} c_y \\ c_z \\ c_x \end{pmatrix} ~~~~~ \boldsymbol c = \boldsymbol a \begin{pmatrix} b_y \\ b_z \\ b_x \end{pmatrix} - \boldsymbol b \begin{pmatrix} a_y \\ a_z \\ a_x \end{pmatrix} \]

Which is equivalent to the common one (source: https://twitter.com/sjb3d/status/563640846671953920):

\[ \boldsymbol a \times \boldsymbol b = \begin{pmatrix}a_yb_z - a_zb_y \\ a_zb_x - a_xb_z \\ a_xb_y - a_yb_x \end{pmatrix} \]

template<class T>
Vector4<T> Magnum::Math::planeEquation(const Vector3<T>& p0, const Vector3<T>& p1, const Vector3<T>& p2)

Create a plane equation from three points.

Assuming the three points form a triangle in a counter-clockwise winding, creates a plane equation in the following form:

\[ ax + by + cz + d = 0 \]