Welcome to Python-flavored Magnum! Please note that, while already being rather stable, this functionality is still considered experimental and some APIs might get changed without preserving full backwards compatibility.

magnum.math module

Math library

In the C++ API, math types are commonly used via typedefs in the root namespace, only library-level generic code uses things like Math::Vector<size, T>. Since Python doesn’t have templates or generics, there are no generic variants in the magnum.math module, all the concrete types are in the root module with the same names as in the C++ variant.

All math structures are instantiated for the most common sizes and types and so they all share a very similar API. As in C++, main differences are between floating-point types and integral types (one having normalization and projection while the other having bitwise operations) and extra convenience methods added for vectors of particular size.

using namespace Magnum;
Vector4i b{3, 4, 5, 6};
b.b() *= 3;
b.xy() += {1, -1};
Debug{} << b;
// Vector(4, 3, 15, 6)

C++

>>> from magnum import *
>>> b = Vector4i(3, 4, 5, 6)
>>> b.b *= 3
>>> b.xy += (1, -1)
>>> b
Vector(4, 3, 15, 6)

Python

As shown above, all math types are constructible from a (nested) tuple of matching type, matching the convenience of C++11 uniform initializers. As another example, a function accepting a Quaternion will accept a ((x, y, z), w) tuple as well, but not (x, y, z, w), as that is not convertible to a pair of a three-component vector and a scalar.

Magnum math vs Python math

Float vs double overloads

Since Python doesn’t really differentiate between 32bit and 64bit doubles, all scalar functions taking or returning a floating-point type (such as the Deg / Rad types, math.pi or math.sin) use the double variant of the underlying C++ API — the extra arithmetic cost is negligible to the Python-to-C++ function call overhead.

On the other hand, matrix and vector types are exposed in both the float and double variants.

Implicit conversions; NumPy compatibility

All vector classes are implicitly convertible from a tuple of correct size and type as well as from/to type implementing the buffer protocol, and these can be also converted back to lists using list comprehensions. This makes them fully compatible with numpy.ndarray, so the following expressions are completely valid:

>>> Matrix4.translation(np.array([1.5, 0.7, 3.3]))
Matrix(1, 0, 0, 1.5,
       0, 1, 0, 0.7,
       0, 0, 1, 3.3,
       0, 0, 0, 1)
>>> m = Matrix4.scaling((0.5, 0.5, 1.0))
>>> np.array(m.diagonal())
array([0.5, 0.5, 1. , 1. ], dtype=float32)

For matrices it’s a bit more complicated, since Magnum is using column-major layout while numpy defaults to row-major (but can do column-major as well). To ensure proper conversions, the buffer protocol implementation for matrix types handles the layout conversion as well. While the matrix are implicitly convertible from/to types implementing a buffer protocol, they are not implicitly convertible from/to plain tuples like vectors are.

To simplify the implementation, Magnum matrices are convertible only from 32-bit and 64-bit floating-point types ('f' and 'd' numpy dtype). In the other direction, unless overridden using dtype or order, the created numpy array matches Magnum data type and layout:

>>> a = Matrix3(np.array(
...     [[1.0, 2.0, 3.0],
...      [4.0, 5.0, 6.0],
...      [7.0, 8.0, 9.0]]))
>>> a[0] # first column
Vector(1, 4, 7)
>>> b = np.array(Matrix3.rotation(Deg(45.0)))
>>> b.strides[0] # column-major storage
4
>>> b[0] # first column, 32-bit floats
array([ 0.70711, -0.70711,  0.     ], dtype=float32)
>>> c = np.array(Matrix3.rotation(Deg(45.0)), order='C', dtype='d')
>>> c.strides[0] # row-major storage (overridden)
24
>>> c[0] # first column, 64-bit floats (overridden)
array([ 0.7071068, -0.7071068,  0.       ])

Major differences to the C++ API

  • All vector and matrix classes implement len(), which is used instead of e.g. Math::Vector::Size. Works on both classes and instances.

  • Math::Matrix3::from() / Math::Matrix4::from() are named Matrix3.from_() / Matrix4.from_() because from is a Python keyword and thus can’t be used as a name.

  • Math::isInf() and Math::isNan() are named math.isinf() and math.isnan() for consistency with the Python math module

  • Math::gather() and Math::scatter() operations are implemented as real swizzles:

    >>> a = Vector4(1.5, 0.3, -1.0, 1.0)
    >>> b = Vector4(7.2, 2.3, 1.1, 0.0)
    >>> a.wxy = b.xwz
    >>> a
    Vector(0, 1.1, -1, 7.2)
  • mat[a][b] = c on matrices doesn’t do the expected thing, use mat[a, b] = c instead

  • Math::BitVector::set() doesn’t exist, use [] instead

  • While both boolean and bitwise operations on Math::BitVector behave the same to ensure consistency in generic code, this is not possible to do in Python. Here the boolean operations behave like if any() was applied before doing the operation.

Static constructors and instance method / property overloads

While not common in Python, the Matrix4.scaling() / Matrix4.rotation() methods mimic the C++ equivalent — calling Matrix4.scaling(vec) will return a scaling matrix, while mat.scaling() returns the 3x3 scaling part of the matrix. With Matrix4.translation, it’s a bit more involved — calling Matrix4.translation(vec) will return a translation matrix, while mat.translation is a read-write property accessing the fourth column of the matrix. Similarly for the Matrix3 class.

Functions

def abs(arg0: Deg, /) -> Deg
Absolute value
def abs(arg0: Rad, /) -> Rad
Absolute value
def abs(arg0: int, /) -> int
Absolute value
def abs(arg0: float, /) -> float
Absolute value
def abs(arg0: Vector2i, /) -> Vector2i
Absolute value
def abs(arg0: Vector3i, /) -> Vector3i
Absolute value
def abs(arg0: Vector4i, /) -> Vector4i
Absolute value
def abs(arg0: Vector2, /) -> Vector2
Absolute value
def abs(arg0: Vector3, /) -> Vector3
Absolute value
def abs(arg0: Vector4, /) -> Vector4
Absolute value
def abs(arg0: Vector2d, /) -> Vector2d
Absolute value
def abs(arg0: Vector3d, /) -> Vector3d
Absolute value
def abs(arg0: Vector4d, /) -> Vector4d
Absolute value
def acos(arg0: float, /) -> Rad
Arc cosine
def angle(normalized_a: Vector2, normalized_b: Vector2) -> Rad
Angle between normalized vectors
def angle(normalized_a: Vector3, normalized_b: Vector3) -> Rad
Angle between normalized vectors
def angle(normalized_a: Vector4, normalized_b: Vector4) -> Rad
Angle between normalized vectors
def angle(normalized_a: Vector2d, normalized_b: Vector2d) -> Rad
Angle between normalized vectors
def angle(normalized_a: Vector3d, normalized_b: Vector3d) -> Rad
Angle between normalized vectors
def angle(normalized_a: Vector4d, normalized_b: Vector4d) -> Rad
Angle between normalized vectors
def asin(arg0: float, /) -> Rad
Arc sine
def atan(arg0: float, /) -> Rad
Arc tangent
def ceil(arg0: Deg, /) -> Deg
Nearest not smaller integer
def ceil(arg0: Rad, /) -> Rad
Nearest not smaller integer
def ceil(arg0: float, /) -> float
Nearest not smaller integer
def ceil(arg0: Vector2, /) -> Vector2
Nearest not smaller integer
def ceil(arg0: Vector3, /) -> Vector3
Nearest not smaller integer
def ceil(arg0: Vector4, /) -> Vector4
Nearest not smaller integer
def ceil(arg0: Vector2d, /) -> Vector2d
Nearest not smaller integer
def ceil(arg0: Vector3d, /) -> Vector3d
Nearest not smaller integer
def ceil(arg0: Vector4d, /) -> Vector4d
Nearest not smaller integer
def clamp(value: Deg, min: Deg, max: Deg) -> Deg
Clamp value
def clamp(value: Rad, min: Rad, max: Rad) -> Rad
Clamp value
def clamp(value: int, min: int, max: int) -> int
Clamp value
def clamp(value: float, min: float, max: float) -> float
Clamp value
def clamp(value: Vector2i, min: Vector2i, max: Vector2i) -> Vector2i
Clamp value
def clamp(value: Vector2i, min: int, max: int) -> Vector2i
Clamp value
def clamp(value: Vector3i, min: Vector3i, max: Vector3i) -> Vector3i
Clamp value
def clamp(value: Vector3i, min: int, max: int) -> Vector3i
Clamp value
def clamp(value: Vector4i, min: Vector4i, max: Vector4i) -> Vector4i
Clamp value
def clamp(value: Vector4i, min: int, max: int) -> Vector4i
Clamp value
def clamp(value: Vector2ui, min: Vector2ui, max: Vector2ui) -> Vector2ui
Clamp value
def clamp(value: Vector2ui, min: int, max: int) -> Vector2ui
Clamp value
def clamp(value: Vector3ui, min: Vector3ui, max: Vector3ui) -> Vector3ui
Clamp value
def clamp(value: Vector3ui, min: int, max: int) -> Vector3ui
Clamp value
def clamp(value: Vector4ui, min: Vector4ui, max: Vector4ui) -> Vector4ui
Clamp value
def clamp(value: Vector4ui, min: int, max: int) -> Vector4ui
Clamp value
def clamp(value: Vector2, min: Vector2, max: Vector2) -> Vector2
Clamp value
def clamp(value: Vector2, min: float, max: float) -> Vector2
Clamp value
def clamp(value: Vector3, min: Vector3, max: Vector3) -> Vector3
Clamp value
def clamp(value: Vector3, min: float, max: float) -> Vector3
Clamp value
def clamp(value: Vector4, min: Vector4, max: Vector4) -> Vector4
Clamp value
def clamp(value: Vector4, min: float, max: float) -> Vector4
Clamp value
def clamp(value: Vector2d, min: Vector2d, max: Vector2d) -> Vector2d
Clamp value
def clamp(value: Vector2d, min: float, max: float) -> Vector2d
Clamp value
def clamp(value: Vector3d, min: Vector3d, max: Vector3d) -> Vector3d
Clamp value
def clamp(value: Vector3d, min: float, max: float) -> Vector3d
Clamp value
def clamp(value: Vector4d, min: Vector4d, max: Vector4d) -> Vector4d
Clamp value
def clamp(value: Vector4d, min: float, max: float) -> Vector4d
Clamp value
def cos(arg0: Rad, /) -> float
Cosine
def cross(arg0: Vector2, arg1: Vector2, /) -> float
2D cross product
def cross(arg0: Vector3, arg1: Vector3, /) -> Vector3
Cross product
def cross(arg0: Vector2d, arg1: Vector2d, /) -> float
2D cross product
def cross(arg0: Vector3d, arg1: Vector3d, /) -> Vector3d
Cross product
def div(x: int, y: int) -> tuple[int, int]
Integer division with remainder
def dot(arg0: Vector2i, arg1: Vector2i, /) -> int
Dot product of two vectors
def dot(arg0: Vector3i, arg1: Vector3i, /) -> int
Dot product of two vectors
def dot(arg0: Vector4i, arg1: Vector4i, /) -> int
Dot product of two vectors
def dot(arg0: Vector2ui, arg1: Vector2ui, /) -> int
Dot product of two vectors
def dot(arg0: Vector3ui, arg1: Vector3ui, /) -> int
Dot product of two vectors
def dot(arg0: Vector4ui, arg1: Vector4ui, /) -> int
Dot product of two vectors
def dot(arg0: Vector2, arg1: Vector2, /) -> float
Dot product of two vectors
def dot(arg0: Vector3, arg1: Vector3, /) -> float
Dot product of two vectors
def dot(arg0: Vector4, arg1: Vector4, /) -> float
Dot product of two vectors
def dot(arg0: Vector2d, arg1: Vector2d, /) -> float
Dot product of two vectors
def dot(arg0: Vector3d, arg1: Vector3d, /) -> float
Dot product of two vectors
def dot(arg0: Vector4d, arg1: Vector4d, /) -> float
Dot product of two vectors
def dot(arg0: Quaternion, arg1: Quaternion, /) -> float
Dot product between two quaternions
def dot(arg0: Quaterniond, arg1: Quaterniond, /) -> float
Dot product between two quaternions
def exp(arg0: float, /) -> float
Natural exponential
def floor(arg0: Deg, /) -> Deg
Nearest not larger integer
def floor(arg0: Rad, /) -> Rad
Nearest not larger integer
def floor(arg0: float, /) -> float
Nearest not larger integer
def floor(arg0: Vector2, /) -> Vector2
Nearest not larger integer
def floor(arg0: Vector3, /) -> Vector3
Nearest not larger integer
def floor(arg0: Vector4, /) -> Vector4
Nearest not larger integer
def floor(arg0: Vector2d, /) -> Vector2d
Nearest not larger integer
def floor(arg0: Vector3d, /) -> Vector3d
Nearest not larger integer
def floor(arg0: Vector4d, /) -> Vector4d
Nearest not larger integer
def fma(arg0: float, arg1: float, arg2: float, /) -> float
Fused multiply-add
def fma(arg0: Vector2, arg1: Vector2, arg2: Vector2, /) -> Vector2
Fused multiply-add
def fma(arg0: Vector3, arg1: Vector3, arg2: Vector3, /) -> Vector3
Fused multiply-add
def fma(arg0: Vector4, arg1: Vector4, arg2: Vector4, /) -> Vector4
Fused multiply-add
def fma(arg0: Vector2d, arg1: Vector2d, arg2: Vector2d, /) -> Vector2d
Fused multiply-add
def fma(arg0: Vector3d, arg1: Vector3d, arg2: Vector3d, /) -> Vector3d
Fused multiply-add
def fma(arg0: Vector4d, arg1: Vector4d, arg2: Vector4d, /) -> Vector4d
Fused multiply-add
def fmod(arg0: Deg, arg1: Deg, /) -> Deg
Floating point division remainder
def fmod(arg0: Rad, arg1: Rad, /) -> Rad
Floating point division remainder
def fmod(arg0: float, arg1: float, /) -> float
Floating point division remainder
def fmod(arg0: Vector2, arg1: Vector2, /) -> Vector2
Floating point division remainder
def fmod(arg0: Vector3, arg1: Vector3, /) -> Vector3
Floating point division remainder
def fmod(arg0: Vector4, arg1: Vector4, /) -> Vector4
Floating point division remainder
def fmod(arg0: Vector2d, arg1: Vector2d, /) -> Vector2d
Floating point division remainder
def fmod(arg0: Vector3d, arg1: Vector3d, /) -> Vector3d
Floating point division remainder
def fmod(arg0: Vector4d, arg1: Vector4d, /) -> Vector4d
Floating point division remainder
def half_angle(normalized_a: Quaternion, normalized_b: Quaternion) -> Rad
Angle between normalized quaternions
def half_angle(normalized_a: Quaterniond, normalized_b: Quaterniond) -> Rad
Angle between normalized quaternions
def intersect(arg0: Range1D, arg1: Range1D, /) -> Range1D
intersect two ranges
def intersect(arg0: Range2D, arg1: Range2D, /) -> Range2D
intersect two ranges
def intersect(arg0: Range3D, arg1: Range3D, /) -> Range3D
intersect two ranges
def intersect(arg0: Range1Di, arg1: Range1Di, /) -> Range1Di
intersect two ranges
def intersect(arg0: Range2Di, arg1: Range2Di, /) -> Range2Di
intersect two ranges
def intersect(arg0: Range3Di, arg1: Range3Di, /) -> Range3Di
intersect two ranges
def intersect(arg0: Range1Dd, arg1: Range1Dd, /) -> Range1Dd
intersect two ranges
def intersect(arg0: Range2Dd, arg1: Range2Dd, /) -> Range2Dd
intersect two ranges
def intersect(arg0: Range3Dd, arg1: Range3Dd, /) -> Range3Dd
intersect two ranges
def intersects(arg0: Range1D, arg1: Range1D, /) -> bool
Whether two ranges intersect
def intersects(arg0: Range2D, arg1: Range2D, /) -> bool
Whether two ranges intersect
def intersects(arg0: Range3D, arg1: Range3D, /) -> bool
Whether two ranges intersect
def intersects(arg0: Range1Di, arg1: Range1Di, /) -> bool
Whether two ranges intersect
def intersects(arg0: Range2Di, arg1: Range2Di, /) -> bool
Whether two ranges intersect
def intersects(arg0: Range3Di, arg1: Range3Di, /) -> bool
Whether two ranges intersect
def intersects(arg0: Range1Dd, arg1: Range1Dd, /) -> bool
Whether two ranges intersect
def intersects(arg0: Range2Dd, arg1: Range2Dd, /) -> bool
Whether two ranges intersect
def intersects(arg0: Range3Dd, arg1: Range3Dd, /) -> bool
Whether two ranges intersect
def isinf(arg0: Deg, /) -> bool
If given number is a positive or negative infinity
def isinf(arg0: Rad, /) -> bool
If given number is a positive or negative infinity
def isinf(arg0: float, /) -> bool
If given number is a positive or negative infinity
def isinf(arg0: Vector2, /) -> BitVector2
If given number is a positive or negative infinity
def isinf(arg0: Vector3, /) -> BitVector3
If given number is a positive or negative infinity
def isinf(arg0: Vector4, /) -> BitVector4
If given number is a positive or negative infinity
def isinf(arg0: Vector2d, /) -> BitVector2
If given number is a positive or negative infinity
def isinf(arg0: Vector3d, /) -> BitVector3
If given number is a positive or negative infinity
def isinf(arg0: Vector4d, /) -> BitVector4
If given number is a positive or negative infinity
def isnan(arg0: Deg, /) -> bool
If given number is a NaN
def isnan(arg0: Rad, /) -> bool
If given number is a NaN
def isnan(arg0: float, /) -> bool
If given number is a NaN
def isnan(arg0: Vector2, /) -> BitVector2
If given number is a NaN
def isnan(arg0: Vector3, /) -> BitVector3
If given number is a NaN
def isnan(arg0: Vector4, /) -> BitVector4
If given number is a NaN
def isnan(arg0: Vector2d, /) -> BitVector2
If given number is a NaN
def isnan(arg0: Vector3d, /) -> BitVector3
If given number is a NaN
def isnan(arg0: Vector4d, /) -> BitVector4
If given number is a NaN
def join(arg0: Range1D, arg1: Range1D, /) -> Range1D
Join two ranges
def join(arg0: Range2D, arg1: Range2D, /) -> Range2D
Join two ranges
def join(arg0: Range3D, arg1: Range3D, /) -> Range3D
Join two ranges
def join(arg0: Range1Di, arg1: Range1Di, /) -> Range1Di
Join two ranges
def join(arg0: Range2Di, arg1: Range2Di, /) -> Range2Di
Join two ranges
def join(arg0: Range3Di, arg1: Range3Di, /) -> Range3Di
Join two ranges
def join(arg0: Range1Dd, arg1: Range1Dd, /) -> Range1Dd
Join two ranges
def join(arg0: Range2Dd, arg1: Range2Dd, /) -> Range2Dd
Join two ranges
def join(arg0: Range3Dd, arg1: Range3Dd, /) -> Range3Dd
Join two ranges
def lerp(a: Deg, b: Deg, t: float) -> Deg
Linear interpolation of two values
def lerp(a: Deg, b: Deg, t: bool) -> Deg
Linear interpolation of two values
def lerp(a: Rad, b: Rad, t: float) -> Rad
Linear interpolation of two values
def lerp(a: Rad, b: Rad, t: bool) -> Rad
Linear interpolation of two values
def lerp(a: BitVector2, b: BitVector2, t: BitVector2) -> BitVector2
Linear interpolation of two values
def lerp(a: BitVector3, b: BitVector3, t: BitVector3) -> BitVector3
Linear interpolation of two values
def lerp(a: BitVector4, b: BitVector4, t: BitVector4) -> BitVector4
Linear interpolation of two values
def lerp(a: int, b: int, t: float) -> int
Linear interpolation of two values
def lerp(a: float, b: float, t: float) -> float
Linear interpolation of two values
def lerp(a: int, b: int, t: bool) -> int
Linear interpolation of two values
def lerp(a: float, b: float, t: bool) -> float
Linear interpolation of two values
def lerp(a: Vector2i, b: Vector2i, t: float) -> Vector2i
Linear interpolation of two values
def lerp(a: Vector2i, b: Vector2i, t: BitVector2) -> Vector2i
Linear interpolation of two values
def lerp(a: Vector2i, b: Vector2i, t: bool) -> Vector2i
Linear interpolation of two values
def lerp(a: Vector3i, b: Vector3i, t: float) -> Vector3i
Linear interpolation of two values
def lerp(a: Vector3i, b: Vector3i, t: BitVector3) -> Vector3i
Linear interpolation of two values
def lerp(a: Vector3i, b: Vector3i, t: bool) -> Vector3i
Linear interpolation of two values
def lerp(a: Vector4i, b: Vector4i, t: float) -> Vector4i
Linear interpolation of two values
def lerp(a: Vector4i, b: Vector4i, t: BitVector4) -> Vector4i
Linear interpolation of two values
def lerp(a: Vector4i, b: Vector4i, t: bool) -> Vector4i
Linear interpolation of two values
def lerp(a: Vector2ui, b: Vector2ui, t: float) -> Vector2ui
Linear interpolation of two values
def lerp(a: Vector2ui, b: Vector2ui, t: BitVector2) -> Vector2ui
Linear interpolation of two values
def lerp(a: Vector2ui, b: Vector2ui, t: bool) -> Vector2ui
Linear interpolation of two values
def lerp(a: Vector3ui, b: Vector3ui, t: float) -> Vector3ui
Linear interpolation of two values
def lerp(a: Vector3ui, b: Vector3ui, t: BitVector3) -> Vector3ui
Linear interpolation of two values
def lerp(a: Vector3ui, b: Vector3ui, t: bool) -> Vector3ui
Linear interpolation of two values
def lerp(a: Vector4ui, b: Vector4ui, t: float) -> Vector4ui
Linear interpolation of two values
def lerp(a: Vector4ui, b: Vector4ui, t: BitVector4) -> Vector4ui
Linear interpolation of two values
def lerp(a: Vector4ui, b: Vector4ui, t: bool) -> Vector4ui
Linear interpolation of two values
def lerp(a: Vector2, b: Vector2, t: float) -> Vector2
Linear interpolation of two values
def lerp(a: Vector2, b: Vector2, t: BitVector2) -> Vector2
Linear interpolation of two values
def lerp(a: Vector2, b: Vector2, t: bool) -> Vector2
Linear interpolation of two values
def lerp(a: Vector3, b: Vector3, t: float) -> Vector3
Linear interpolation of two values
def lerp(a: Vector3, b: Vector3, t: BitVector3) -> Vector3
Linear interpolation of two values
def lerp(a: Vector3, b: Vector3, t: bool) -> Vector3
Linear interpolation of two values
def lerp(a: Vector4, b: Vector4, t: float) -> Vector4
Linear interpolation of two values
def lerp(a: Vector4, b: Vector4, t: BitVector4) -> Vector4
Linear interpolation of two values
def lerp(a: Vector4, b: Vector4, t: bool) -> Vector4
Linear interpolation of two values
def lerp(a: Vector2d, b: Vector2d, t: float) -> Vector2d
Linear interpolation of two values
def lerp(a: Vector2d, b: Vector2d, t: BitVector2) -> Vector2d
Linear interpolation of two values
def lerp(a: Vector2d, b: Vector2d, t: bool) -> Vector2d
Linear interpolation of two values
def lerp(a: Vector3d, b: Vector3d, t: float) -> Vector3d
Linear interpolation of two values
def lerp(a: Vector3d, b: Vector3d, t: BitVector3) -> Vector3d
Linear interpolation of two values
def lerp(a: Vector3d, b: Vector3d, t: bool) -> Vector3d
Linear interpolation of two values
def lerp(a: Vector4d, b: Vector4d, t: float) -> Vector4d
Linear interpolation of two values
def lerp(a: Vector4d, b: Vector4d, t: BitVector4) -> Vector4d
Linear interpolation of two values
def lerp(a: Vector4d, b: Vector4d, t: bool) -> Vector4d
Linear interpolation of two values
def lerp(normalized_a: Quaternion, normalized_b: Quaternion, t: float) -> Quaternion
Linear interpolation of two quaternions
def lerp(normalized_a: Quaterniond, normalized_b: Quaterniond, t: float) -> Quaterniond
Linear interpolation of two quaternions
def lerp_inverted(a: Deg, b: Deg, lerp: Deg) -> float
Inverse linear interpolation of two values
def lerp_inverted(a: Rad, b: Rad, lerp: Rad) -> float
Inverse linear interpolation of two values
def lerp_inverted(a: float, b: float, lerp: float) -> float
Inverse linear interpolation of two values
def lerp_inverted(a: Vector2, b: Vector2, t: Vector2) -> Vector2
Inverse linear interpolation of two values
def lerp_inverted(a: Vector3, b: Vector3, t: Vector3) -> Vector3
Inverse linear interpolation of two values
def lerp_inverted(a: Vector4, b: Vector4, t: Vector4) -> Vector4
Inverse linear interpolation of two values
def lerp_inverted(a: Vector2d, b: Vector2d, t: Vector2d) -> Vector2d
Inverse linear interpolation of two values
def lerp_inverted(a: Vector3d, b: Vector3d, t: Vector3d) -> Vector3d
Inverse linear interpolation of two values
def lerp_inverted(a: Vector4d, b: Vector4d, t: Vector4d) -> Vector4d
Inverse linear interpolation of two values
def lerp_shortest_path(normalized_a: Quaternion, normalized_b: Quaternion, t: float) -> Quaternion
Linear shortest-path interpolation of two quaternions
def lerp_shortest_path(normalized_a: Quaterniond, normalized_b: Quaterniond, t: float) -> Quaterniond
Linear shortest-path interpolation of two quaternions
def log(base: int, number: int) -> int
Integral algorithm
def log(arg0: float, /) -> float
Natural algorithm
def log2(arg0: int, /) -> int
Base-2 integral algorithm
def max(value: Deg, min: Deg) -> Deg
Maximum
def max(value: Rad, min: Rad) -> Rad
Maximum
def max(value: int, min: int) -> int
Maximum
def max(value: float, min: float) -> float
Maximum
def max(value: Vector2i, max: Vector2i) -> Vector2i
Maximum
def max(value: Vector2i, max: int) -> Vector2i
Maximum
def max(value: Vector3i, max: Vector3i) -> Vector3i
Maximum
def max(value: Vector3i, max: int) -> Vector3i
Maximum
def max(value: Vector4i, max: Vector4i) -> Vector4i
Maximum
def max(value: Vector4i, max: int) -> Vector4i
Maximum
def max(value: Vector2ui, max: Vector2ui) -> Vector2ui
Maximum
def max(value: Vector2ui, max: int) -> Vector2ui
Maximum
def max(value: Vector3ui, max: Vector3ui) -> Vector3ui
Maximum
def max(value: Vector3ui, max: int) -> Vector3ui
Maximum
def max(value: Vector4ui, max: Vector4ui) -> Vector4ui
Maximum
def max(value: Vector4ui, max: int) -> Vector4ui
Maximum
def max(value: Vector2, max: Vector2) -> Vector2
Maximum
def max(value: Vector2, max: float) -> Vector2
Maximum
def max(value: Vector3, max: Vector3) -> Vector3
Maximum
def max(value: Vector3, max: float) -> Vector3
Maximum
def max(value: Vector4, max: Vector4) -> Vector4
Maximum
def max(value: Vector4, max: float) -> Vector4
Maximum
def max(value: Vector2d, max: Vector2d) -> Vector2d
Maximum
def max(value: Vector2d, max: float) -> Vector2d
Maximum
def max(value: Vector3d, max: Vector3d) -> Vector3d
Maximum
def max(value: Vector3d, max: float) -> Vector3d
Maximum
def max(value: Vector4d, max: Vector4d) -> Vector4d
Maximum
def max(value: Vector4d, max: float) -> Vector4d
Maximum
def min(value: Deg, min: Deg) -> Deg
Minimum
def min(value: Rad, min: Rad) -> Rad
Minimum
def min(value: int, min: int) -> int
Minimum
def min(value: float, min: float) -> float
Minimum
def min(value: Vector2i, min: Vector2i) -> Vector2i
Minimum
def min(value: Vector2i, min: int) -> Vector2i
Minimum
def min(value: Vector3i, min: Vector3i) -> Vector3i
Minimum
def min(value: Vector3i, min: int) -> Vector3i
Minimum
def min(value: Vector4i, min: Vector4i) -> Vector4i
Minimum
def min(value: Vector4i, min: int) -> Vector4i
Minimum
def min(value: Vector2ui, min: Vector2ui) -> Vector2ui
Minimum
def min(value: Vector2ui, min: int) -> Vector2ui
Minimum
def min(value: Vector3ui, min: Vector3ui) -> Vector3ui
Minimum
def min(value: Vector3ui, min: int) -> Vector3ui
Minimum
def min(value: Vector4ui, min: Vector4ui) -> Vector4ui
Minimum
def min(value: Vector4ui, min: int) -> Vector4ui
Minimum
def min(value: Vector2, min: Vector2) -> Vector2
Minimum
def min(value: Vector2, min: float) -> Vector2
Minimum
def min(value: Vector3, min: Vector3) -> Vector3
Minimum
def min(value: Vector3, min: float) -> Vector3
Minimum
def min(value: Vector4, min: Vector4) -> Vector4
Minimum
def min(value: Vector4, min: float) -> Vector4
Minimum
def min(value: Vector2d, min: Vector2d) -> Vector2d
Minimum
def min(value: Vector2d, min: float) -> Vector2d
Minimum
def min(value: Vector3d, min: Vector3d) -> Vector3d
Minimum
def min(value: Vector3d, min: float) -> Vector3d
Minimum
def min(value: Vector4d, min: Vector4d) -> Vector4d
Minimum
def min(value: Vector4d, min: float) -> Vector4d
Minimum
def minmax(arg0: Deg, arg1: Deg, /) -> tuple[Deg, Deg]
Minimum and maximum of two values
def minmax(arg0: Rad, arg1: Rad, /) -> tuple[Rad, Rad]
Minimum and maximum of two values
def minmax(arg0: int, arg1: int, /) -> tuple[int, int]
Minimum and maximum of two values
def minmax(arg0: float, arg1: float, /) -> tuple[float, float]
Minimum and maximum of two values
def minmax(arg0: Vector2i, arg1: Vector2i, /) -> tuple[Vector2i, Vector2i]
Minimum and maximum of two values
def minmax(arg0: Vector3i, arg1: Vector3i, /) -> tuple[Vector3i, Vector3i]
Minimum and maximum of two values
def minmax(arg0: Vector4i, arg1: Vector4i, /) -> tuple[Vector4i, Vector4i]
Minimum and maximum of two values
def minmax(arg0: Vector2ui, arg1: Vector2ui, /) -> tuple[Vector2ui, Vector2ui]
Minimum and maximum of two values
def minmax(arg0: Vector3ui, arg1: Vector3ui, /) -> tuple[Vector3ui, Vector3ui]
Minimum and maximum of two values
def minmax(arg0: Vector4ui, arg1: Vector4ui, /) -> tuple[Vector4ui, Vector4ui]
Minimum and maximum of two values
def minmax(arg0: Vector2, arg1: Vector2, /) -> tuple[Vector2, Vector2]
Minimum and maximum of two values
def minmax(arg0: Vector3, arg1: Vector3, /) -> tuple[Vector3, Vector3]
Minimum and maximum of two values
def minmax(arg0: Vector4, arg1: Vector4, /) -> tuple[Vector4, Vector4]
Minimum and maximum of two values
def minmax(arg0: Vector2d, arg1: Vector2d, /) -> tuple[Vector2d, Vector2d]
Minimum and maximum of two values
def minmax(arg0: Vector3d, arg1: Vector3d, /) -> tuple[Vector3d, Vector3d]
Minimum and maximum of two values
def minmax(arg0: Vector4d, arg1: Vector4d, /) -> tuple[Vector4d, Vector4d]
Minimum and maximum of two values
def popcount(arg0: int, /) -> int
Count of bits set in a number
def pow(arg0: float, arg1: float, /) -> float
Power
def round(arg0: Deg, /) -> Deg
Round value to nearest integer
def round(arg0: Rad, /) -> Rad
Round value to nearest integer
def round(arg0: float, /) -> float
Round value to nearest integer
def round(arg0: Vector2, /) -> Vector2
Round value to nearest integer
def round(arg0: Vector3, /) -> Vector3
Round value to nearest integer
def round(arg0: Vector4, /) -> Vector4
Round value to nearest integer
def round(arg0: Vector2d, /) -> Vector2d
Round value to nearest integer
def round(arg0: Vector3d, /) -> Vector3d
Round value to nearest integer
def round(arg0: Vector4d, /) -> Vector4d
Round value to nearest integer
def select(a: Deg, b: Deg, t: float) -> Deg
Constant interpolation of two values
def select(a: Rad, b: Rad, t: float) -> Rad
Constant interpolation of two values
def select(a: int, b: int, t: float) -> int
Constant interpolation of two values
def select(a: float, b: float, t: float) -> float
Constant interpolation of two values
def select(a: Vector2i, b: Vector2i, t: float) -> Vector2i
Constant interpolation of two values
def select(a: Vector3i, b: Vector3i, t: float) -> Vector3i
Constant interpolation of two values
def select(a: Vector4i, b: Vector4i, t: float) -> Vector4i
Constant interpolation of two values
def select(a: Vector2ui, b: Vector2ui, t: float) -> Vector2ui
Constant interpolation of two values
def select(a: Vector3ui, b: Vector3ui, t: float) -> Vector3ui
Constant interpolation of two values
def select(a: Vector4ui, b: Vector4ui, t: float) -> Vector4ui
Constant interpolation of two values
def select(a: Vector2, b: Vector2, t: float) -> Vector2
Constant interpolation of two values
def select(a: Vector3, b: Vector3, t: float) -> Vector3
Constant interpolation of two values
def select(a: Vector4, b: Vector4, t: float) -> Vector4
Constant interpolation of two values
def select(a: Vector2d, b: Vector2d, t: float) -> Vector2d
Constant interpolation of two values
def select(a: Vector3d, b: Vector3d, t: float) -> Vector3d
Constant interpolation of two values
def select(a: Vector4d, b: Vector4d, t: float) -> Vector4d
Constant interpolation of two values
def sign(arg0: Deg, /) -> float
Sign
def sign(arg0: Rad, /) -> float
Sign
def sign(arg0: int, /) -> int
Sign
def sign(arg0: float, /) -> float
Sign
def sign(arg0: Vector2i, /) -> Vector2i
Sign
def sign(arg0: Vector3i, /) -> Vector3i
Sign
def sign(arg0: Vector4i, /) -> Vector4i
Sign
def sign(arg0: Vector2, /) -> Vector2
Sign
def sign(arg0: Vector3, /) -> Vector3
Sign
def sign(arg0: Vector4, /) -> Vector4
Sign
def sign(arg0: Vector2d, /) -> Vector2d
Sign
def sign(arg0: Vector3d, /) -> Vector3d
Sign
def sign(arg0: Vector4d, /) -> Vector4d
Sign
def sin(arg0: Rad, /) -> float
Sine
def sincos(arg0: Rad, /) -> tuple[float, float]
Sine and cosine
def slerp(normalized_a: Quaternion, normalized_b: Quaternion, t: float) -> Quaternion
Spherical linear interpolation of two quaternions
def slerp(normalized_a: Quaterniond, normalized_b: Quaterniond, t: float) -> Quaterniond
Spherical linear interpolation of two quaternions
def slerp_shortest_path(normalized_a: Quaternion, normalized_b: Quaternion, t: float) -> Quaternion
Spherical linear shortest-path interpolation of two quaternions
def slerp_shortest_path(normalized_a: Quaterniond, normalized_b: Quaterniond, t: float) -> Quaterniond
Spherical linear shortest-path interpolation of two quaternions
def sqrt(arg0: float, /) -> float
Square root
def sqrt_inverted(arg0: float, /) -> float
Square root
def tan(arg0: Rad, /) -> float
Tangent

Data

e = 2.718281828459045
Euler’s number
inf = inf
Positive \infty
nan = nan
Quiet NaN
pi = 3.141592653589793
\pi
pi_half = 1.5707963267948966
Half of a \pi
pi_quarter = 0.7853981633974483
Quarter of a \pi
sqrt2 = 1.414213562373095
Square root of 2
sqrt3 = 1.7320508075688772
Square root of 3
sqrt_half = 0.7071067811865475
Square root of \frac{1}{2}
tau = 6.283185307179586
\tau , or 2 \pi

Function documentation

def magnum.math.angle(normalized_a: Vector2, normalized_b: Vector2) -> Rad

Angle between normalized vectors

Exceptions
ValueError If either of the vectors is not normalized

def magnum.math.angle(normalized_a: Vector3, normalized_b: Vector3) -> Rad

Angle between normalized vectors

Exceptions
ValueError If either of the vectors is not normalized

def magnum.math.angle(normalized_a: Vector4, normalized_b: Vector4) -> Rad

Angle between normalized vectors

Exceptions
ValueError If either of the vectors is not normalized

def magnum.math.angle(normalized_a: Vector2d, normalized_b: Vector2d) -> Rad

Angle between normalized vectors

Exceptions
ValueError If either of the vectors is not normalized

def magnum.math.angle(normalized_a: Vector3d, normalized_b: Vector3d) -> Rad

Angle between normalized vectors

Exceptions
ValueError If either of the vectors is not normalized

def magnum.math.angle(normalized_a: Vector4d, normalized_b: Vector4d) -> Rad

Angle between normalized vectors

Exceptions
ValueError If either of the vectors is not normalized

def magnum.math.half_angle(normalized_a: Quaternion, normalized_b: Quaternion) -> Rad

Angle between normalized quaternions

Exceptions
ValueError If either of the quaternions is not normalized

def magnum.math.half_angle(normalized_a: Quaterniond, normalized_b: Quaterniond) -> Rad

Angle between normalized quaternions

Exceptions
ValueError If either of the quaternions is not normalized

def magnum.math.lerp(normalized_a: Quaternion, normalized_b: Quaternion, t: float) -> Quaternion

Linear interpolation of two quaternions

Exceptions
ValueError If either of the quaternions is not normalized

def magnum.math.lerp(normalized_a: Quaterniond, normalized_b: Quaterniond, t: float) -> Quaterniond

Linear interpolation of two quaternions

Exceptions
ValueError If either of the quaternions is not normalized

def magnum.math.lerp_shortest_path(normalized_a: Quaternion, normalized_b: Quaternion, t: float) -> Quaternion

Linear shortest-path interpolation of two quaternions

Exceptions
ValueError If either of the quaternions is not normalized

def magnum.math.lerp_shortest_path(normalized_a: Quaterniond, normalized_b: Quaterniond, t: float) -> Quaterniond

Linear shortest-path interpolation of two quaternions

Exceptions
ValueError If either of the quaternions is not normalized

def magnum.math.slerp(normalized_a: Quaternion, normalized_b: Quaternion, t: float) -> Quaternion

Spherical linear interpolation of two quaternions

Exceptions
ValueError If either of the quaternions is not normalized

def magnum.math.slerp(normalized_a: Quaterniond, normalized_b: Quaterniond, t: float) -> Quaterniond

Spherical linear interpolation of two quaternions

Exceptions
ValueError If either of the quaternions is not normalized

def magnum.math.slerp_shortest_path(normalized_a: Quaternion, normalized_b: Quaternion, t: float) -> Quaternion

Spherical linear shortest-path interpolation of two quaternions

Exceptions
ValueError If either of the quaternions is not normalized

def magnum.math.slerp_shortest_path(normalized_a: Quaterniond, normalized_b: Quaterniond, t: float) -> Quaterniond

Spherical linear shortest-path interpolation of two quaternions

Exceptions
ValueError If either of the quaternions is not normalized