namespace
MathMath library.
Contents
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 Geometry
- Geometry library.
- namespace Literals
- Math literals.
Classes
-
template<UnsignedInt order, UnsignedInt dimensions, class T>class Bezier
- Bézier curve.
-
template<std::class BoolVector
size_t size> - 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>class Complex
- Complex number.
-
template<class T>struct Constants
- Numeric constants.
-
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<std::class Matrix
size_t size, class T> - 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
- Two-dimensional range.
-
template<std::class RectangularMatrix
size_t cols, std:: size_t rows, class T> - Rectangular matrix.
-
template<class T>struct TypeTraits
- Traits class for numeric types.
-
template<template<class> class Derived, class T>class Unit
- Base class for units.
-
template<std::class Vector
size_t size, class T> - 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 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.
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::auto operator<<(Corrade::
size_t size> 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 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<<(Corrade::
Utility:: Debug& debug, const Complex<T>& value) -> Corrade:: Utility:: Debug& - Debug output operator.
-
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 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.
- 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<class Integral>auto div(Integral x, Integral y) -> std::
pair<Integral, Integral> - Integer division with remainder.
-
template<class T>auto isInf(T value) -> bool
- If given number is a positive or negative infinity.
-
template<class T>auto isNan(T value) -> bool
- If given number is NaN.
-
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.
-
auto operator<<(Corrade::
Utility:: Debug& debug, Half value) -> Corrade:: Utility:: Debug& - Debug output operator.
- 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 FloatingPoint, class Integral>auto normalize(const Integral& value) -> FloatingPoint deprecated
- Unpack integral value 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<class Integral, class FloatingPoint>auto denormalize(const FloatingPoint& value) -> Integral deprecated
- Pack floating-point value into an integer representation.
-
template<std::auto packHalf(const Vector<size, Float>& value) -> Vector<size, UnsignedShort>
size_t size> -
template<std::auto unpackHalf(const Vector<size, UnsignedShort>& value) -> Vector<size, Float>
size_t size> -
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 slerp(const Quaternion<T>& normalizedA, const Quaternion<T>& normalizedB, T t) -> Quaternion<T>
- Spherical linear 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 operator<<(Corrade::
Utility:: Debug& debug, const Range<dimensions, T>& value) -> Corrade:: Utility:: Debug& - Debug output operator.
-
template<std::auto operator<<(Corrade::
size_t cols, std:: size_t rows, class T> 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::auto dot(const Vector<size, T>& a, const Vector<size, T>& b) -> T
size_t size, class T> - Dot product of two vectors.
-
template<std::auto angle(const Vector<size, T>& normalizedA, const Vector<size, T>& normalizedB) -> Rad<T>
size_t size, class T> - Angle between normalized vectors.
-
template<std::auto operator<<(Corrade::
size_t size, class T> 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.
Variables
- NoInitT NoInit constexpr
- No initialization tag.
- ZeroInitT ZeroInit constexpr
- Zero initialization tag.
- IdentityInitT IdentityInit constexpr
- Identity initialization tag.
Scalar/vector functions
These functions are overloaded for both scalar and vector types. Scalar versions function exactly as their possible STL equivalents, vector overloads perform the operations component-wise.
-
template<UnsignedInt exponent, class T>auto pow(T base) -> T constexpr
- Integral power.
-
template<class T>auto pow(T base, T exponent) -> T
- Power.
-
template<class T>auto min(T value, T min) -> T
- Minimum.
-
template<std::auto min(const Vector<size, T>& value, T min) -> Vector<size, T>
size_t size, class T> -
template<class T>auto min(Corrade::
Containers:: ArrayView<const T> range) -> T - Minimum of a range.
-
template<class T>auto min(std::
initializer_list<T> list) -> T -
template<class T>auto max(T value, T max) -> T
- Maximum.
-
template<std::auto max(const Vector<size, T>& value, T max) -> Vector<size, T>
size_t size, class T> -
template<class T>auto max(Corrade::
Containers:: ArrayView<const T> range) -> T - Maximum of a range.
-
template<class T>auto max(std::
initializer_list<T> list) -> T -
template<class T>auto minmax(const T& a, const T& b) -> std::
pair<T, T> - Minimum and maximum of two values.
-
template<class T>auto minmax(Corrade::
Containers:: ArrayView<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, class U>auto clamp(const T& value, const T& min, const T& max) -> T
- Clamp value.
-
template<std::auto clamp(const Vector<size, T>& value, T min, T max) -> Vector<size, T>
size_t size, class T> -
template<class T>auto sign(const T scalar) -> T
- Sign.
-
template<class T>auto abs(const T& a) -> T
- Absolute value.
-
template<class T>auto floor(const T& a) -> T
- Nearest not larger integer.
-
template<class T>auto round(const T& a) -> T
- Round value to nearest integer.
-
template<class T>auto ceil(const T& a) -> T
- Nearest not smaller integer.
-
template<class T>auto sqrt(const T& a) -> T
- Square root.
-
template<class T>auto sqrtInverted(const T& a) -> T
- Inverse square root.
-
template<class T, class U>auto lerp(const T& a, const T& b, U t) -> T
- Linear interpolation of two values.
-
template<std::auto lerp(const Vector<size, T>& a, const Vector<size, T>& b, const BoolVector<size>& t) -> Vector<size, T>
size_t size, class T> -
template<std::auto lerp(const BoolVector<size>& a, const BoolVector<size>& b, const BoolVector<size>& t) -> BoolVector<size>
size_t size> -
template<class T>auto lerpInverted(const T& a, const T& b, const T& lerp) -> T
- Inverse linear interpolation of two values.
-
template<class T>auto fma(const T& a, const T& b, const T& c) -> T
- Fused multiply-add.
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:: 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.
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.
Corrade:: Utility:: Debug& Magnum:: Math:: operator<<(Corrade:: Utility:: Debug& debug,
const Color3<UnsignedByte>& value)
Debug output operator.
Prints the value as hex color (e.g. #ff33aa
). Other underlying types are handled by operator<<(Corrade::
Corrade:: Utility:: Debug& Magnum:: Math:: operator<<(Corrade:: Utility:: Debug& debug,
const Color4<UnsignedByte>& value)
Debug output operator.
Prints the value as hex color (e.g. #9933aaff
). Other underlying types are handled by operator<<(Corrade::
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 Dual<T>& value)
Debug output operator.
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 ) |
Expects that both dual quaternions are normalized.
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.
UnsignedInt Magnum:: Math:: log(UnsignedInt base,
UnsignedInt number)
Integral logarithm.
Returns integral logarithm of given number with given base.
UnsignedInt Magnum:: Math:: log2(UnsignedInt number)
Base-2 integral logarithm.
Returns integral logarithm of given number with base 2
.
template<class T>
T Magnum:: Math:: log(T number)
Natural logarithm.
Returns natural (base ) logarithm of given number.
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>
bool Magnum:: Math:: isInf(T value)
If given number is a positive or negative infinity.
template<class T>
bool Magnum:: Math:: isNan(T value)
If given number is NaN.
Equivalent to value != value
.
Corrade:: Utility:: Debug& Magnum:: Math:: operator<<(Corrade:: Utility:: Debug& debug,
Half value)
Debug output operator.
Float Magnum:: Math:: unpackHalf(UnsignedShort value)
Unpack 16-bit half-float value into 32-bit float representation.
See Wikipedia for more information about half floats. NaNs are converted to NaNs and infinities to infinities, though their exact bit pattern is not preserved.
Implementation based on CC0 / public domain code by Fabian Giesen, https:/
UnsignedShort Magnum:: Math:: packHalf(Float value)
Pack 32-bit float value into 16-bit half-float representation.
See Wikipedia for more information about half floats. NaNs are converted to NaNs and infinities to infinities, though their exact bit pattern is not preserved. Note that rounding mode is unspecified in order to save some cycles.
Implementation based on CC0 / public domain code by Fabian Giesen, https:/
template<class FloatingPoint, class Integral>
FloatingPoint Magnum:: Math:: unpack(const Integral& value)
Unpack integral value into a floating-point representation.
Converts integral value from full range of given unsigned integral type to value in range or from signed integral to range .
template<class FloatingPoint, class Integral, UnsignedInt bits>
FloatingPoint Magnum:: Math:: unpack(const Integral& value)
Unpack integer bits into a floating-point representation.
Alternative to the above with ability to specify how many bits of the integral representation to use. Example usage:
Float a = Math::unpack<Float, UnsignedShort>(8191); // 0.124987f Float b = Math::unpack<Float, UnsignedShort, 14>(8191); // 0.499969f Float b = Math::unpack<Float, 14>(8191u); // 0.499969f Float b = Math::unpack<Float, 14>(8191); // 1.0f
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class FloatingPoint, class Integral>
FloatingPoint Magnum:: Math:: normalize(const Integral& value)
Unpack integral value into a floating-point representation.
template<class Integral, class FloatingPoint>
Integral Magnum:: Math:: pack(const FloatingPoint& value)
Pack floating-point value into an integer representation.
Converts floating-point value in range to full range of given unsigned* integral type or range to full range of given signed integral type.
template<class Integral, UnsignedInt bits, class FloatingPoint>
Integral Magnum:: Math:: pack(FloatingPoint value)
Pack floating-point value into integer bits.
Alternative to the above with ability to specify how many bits of the integral representation to use. Example usage:
auto a = Math::pack<UnsignedShort>(0.5f); // 32767 auto b = Math::pack<UnsignedShort, 14>(0.5f); // 8191
template<class Integral, class FloatingPoint>
Integral Magnum:: Math:: denormalize(const FloatingPoint& value)
Pack floating-point value into an integer representation.
template<std:: size_t size>
Vector<size, UnsignedShort> Magnum:: Math:: packHalf(const Vector<size, Float>& value)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<std:: size_t size>
Vector<size, Float> Magnum:: Math:: unpackHalf(const Vector<size, UnsignedShort>& value)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
T Magnum:: Math:: dot(const Quaternion<T>& a,
const Quaternion<T>& b)
Dot product between two quaternions.
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.
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 ) |
Expects that both quaternions are normalized.
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 ) |
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>
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 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 = 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.
template<std:: size_t size, class T>
Rad<T> Magnum:: Math:: angle(const Vector<size, T>& normalizedA,
const Vector<size, T>& normalizedB)
Angle between normalized vectors.
Expects that both vectors are normalized.
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.
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:
Which is equivalent to the common one (source: https:/
template<UnsignedInt exponent, class T>
T Magnum:: Math:: pow(T base) constexpr
Integral power.
Returns integral power of base to the exponent.
template<class T>
T Magnum:: Math:: pow(T base,
T exponent)
Power.
Returns power of base
to the exponent
.
template<class T>
T Magnum:: Math:: min(T value,
T min)
Minimum.
NaNs passed in value
parameter are propagated.
template<std:: size_t size, class T>
Vector<size, T> Magnum:: Math:: min(const Vector<size, T>& value,
T min)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
T Magnum:: Math:: min(Corrade:: Containers:: ArrayView<const T> range)
Minimum of a range.
If the range is empty, returns default-constructed value.
template<class T>
T Magnum:: Math:: min(std:: initializer_list<T> list)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
T Magnum:: Math:: max(T value,
T max)
Maximum.
NaNs passed in value
parameter are propagated.
template<std:: size_t size, class T>
Vector<size, T> Magnum:: Math:: max(const Vector<size, T>& value,
T max)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
T Magnum:: Math:: max(Corrade:: Containers:: ArrayView<const T> range)
Maximum of a range.
If the range is empty, returns default-constructed value.
template<class T>
T Magnum:: Math:: max(std:: initializer_list<T> list)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
std:: pair<T, T> Magnum:: Math:: minmax(Corrade:: Containers:: ArrayView<const T> range)
Minimum and maximum of a range.
If the range is empty, returns default-constructed values.
template<class T>
std:: pair<T, T> Magnum:: Math:: minmax(std:: initializer_list<T> list)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T, class U>
T Magnum:: Math:: clamp(const T& value,
const T& min,
const T& max)
Clamp value.
Values smaller than min
are set to min
, values larger than max
are set to max
. Equivalent to:
Math::min(Math::max(value, min), max)
NaNs passed in value
parameter are propagated.
template<std:: size_t size, class T>
Vector<size, T> Magnum:: Math:: clamp(const Vector<size, T>& value,
T min,
T max)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
T Magnum:: Math:: sign(const T scalar)
Sign.
Returns 1
if x
> 0, 0
if x
= 0 and -1
if x
< 0.
template<class T>
T Magnum:: Math:: sqrt(const T& a)
Square root.
template<class T>
T Magnum:: Math:: sqrtInverted(const T& a)
Inverse square root.
template<class T, class U>
T Magnum:: Math:: lerp(const T& a,
const T& b,
U t)
Linear interpolation of two values.
Parameters | |
---|---|
a | First value |
b | Second value |
t | Interpolation phase (from range ) |
The interpolation for vectors is done as in following, similarly for scalars:
template<std:: size_t size, class T>
Vector<size, T> Magnum:: Math:: lerp(const Vector<size, T>& a,
const Vector<size, T>& b,
const BoolVector<size>& t)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Similar to the above, but instead of multiplication and addition it just does component-wise selection from either a
or b
based on values in t
.
template<std:: size_t size>
BoolVector<size> Magnum:: Math:: lerp(const BoolVector<size>& a,
const BoolVector<size>& b,
const BoolVector<size>& t)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
T Magnum:: Math:: lerpInverted(const T& a,
const T& b,
const T& lerp)
Inverse linear interpolation of two values.
Parameters | |
---|---|
a | First value |
b | Second value |
lerp | Interpolated value |
Returns interpolation phase t:
template<class T>
T Magnum:: Math:: fma(const T& a,
const T& b,
const T& c)
Fused multiply-add.
Computes and returns . On some architectures might be faster than doing the computation manually.
Variable documentation
IdentityInitT Magnum:: Math:: IdentityInit constexpr
Identity initialization tag.
Use for construction with transformation set to identity.