Skip to content

math

Vector3D

Python
Vector3D(x: T = 0, y: T = 0, z: T = 0)

A generic 3D vector class supporting basic vector operations.

ATTRIBUTE DESCRIPTION
x

X coordinate

TYPE: T

y

Y coordinate

TYPE: T

z

Z coordinate

TYPE: T

to_floor

Python
to_floor() -> Vector3D[int]

Convert each component of the vector to its floored integer value.

RETURNS DESCRIPTION
Vector3D[int]

Vector with integer components

to_2d

Python
to_2d() -> Vector2D[T]

Convert a 3D vector to a 2D vector by removing the Y (height) component.

RETURNS DESCRIPTION
Vector2D[int]

A 2D vector with the X and Z components of this vector

magnitude

Python
magnitude() -> float

Calculate the magnitude (length) of the vector.

RETURNS DESCRIPTION
float

Magnitude of the vector

magnitude_squared

Python
magnitude_squared() -> Union[int, float]

Calculate the squared magnitude of the vector (more efficient than magnitude).

RETURNS DESCRIPTION
Union[int, float]

Squared magnitude of the vector

normalize

Python
normalize() -> Vector3D[float]

Return a normalized (unit) vector in the same direction.

RETURNS DESCRIPTION
Vector3D[float]

Normalized vector with magnitude 1, or zero vector if original magnitude is 0

distance_to

Python
distance_to(other: Vector3D[T]) -> float

Calculate the Euclidean distance to another vector.

PARAMETER DESCRIPTION
other

Target vector

TYPE: Vector3D[T]

RETURNS DESCRIPTION
float

Distance between the two vectors

copy

Python
copy() -> Vector3D[T]

Return a copy of the vector.

RETURNS DESCRIPTION
Vector3D[T]

A new Vector3D instance with the same components.

dot

Python
dot(other: Vector3D[T]) -> float

Calculate the dot product with another vector.

PARAMETER DESCRIPTION
other

The other vector

TYPE: Vector3D[T]

RETURNS DESCRIPTION
float

The dot product result

cross

Python
cross(other: Vector3D[T]) -> Vector3D[float]

Calculate the cross product with another vector.

PARAMETER DESCRIPTION
other

The other vector

TYPE: Vector3D[T]

RETURNS DESCRIPTION
Vector3D[float]

The cross product result

is_zero

Python
is_zero(tolerance: float = 1e-06) -> bool

Check if vector is approximately zero within tolerance.

PARAMETER DESCRIPTION
tolerance

Tolerance for zero check (default: 1e-6)

TYPE: float DEFAULT: 1e-06

RETURNS DESCRIPTION
bool

True if vector magnitude is below tolerance

lerp

Python
lerp(other: Vector3D[T], t: float) -> Vector3D[float]

Linear interpolation between this vector and another.

PARAMETER DESCRIPTION
other

Target vector

TYPE: Vector3D[T]

t

Interpolation factor (0.0 = this vector, 1.0 = other vector)

TYPE: float

RETURNS DESCRIPTION
Vector3D[float]

Interpolated vector

clamp_magnitude

Python
clamp_magnitude(max_magnitude: float) -> Vector3D[float]

Clamp vector magnitude to maximum value.

PARAMETER DESCRIPTION
max_magnitude

Maximum allowed magnitude

TYPE: float

RETURNS DESCRIPTION
Vector3D[float]

Vector with clamped magnitude

angle_to

Python
angle_to(other: Vector3D[T]) -> float

Calculate the angle between this vector and another in radians.

PARAMETER DESCRIPTION
other

Target vector

TYPE: Vector3D[T]

RETURNS DESCRIPTION
float

Angle in radians (0 to π)

project_onto

Python
project_onto(other: Vector3D[T]) -> Vector3D[float]

Project this vector onto another vector.

PARAMETER DESCRIPTION
other

Vector to project onto

TYPE: Vector3D[T]

RETURNS DESCRIPTION
Vector3D[float]

Projected vector

reflect

Python
reflect(normal: Vector3D[T]) -> Vector3D[float]

Reflect this vector across a surface with given normal.

PARAMETER DESCRIPTION
normal

Surface normal vector (should be normalized)

TYPE: Vector3D[T]

RETURNS DESCRIPTION
Vector3D[float]

Reflected vector

average staticmethod

Python
average(vectors: List[Vector3D[T]]) -> Vector3D[float]

Calculate the average of multiple vectors.

PARAMETER DESCRIPTION
vectors

List of vectors to average

TYPE: List[Vector3D[T]]

RETURNS DESCRIPTION
Vector3D[float]

Average vector, or zero vector if list is empty


Vector2D

Python
Vector2D(x: T = 0, y: T = 0)

A generic 2D vector class supporting basic vector operations.

ATTRIBUTE DESCRIPTION
x

X coordinate

TYPE: T

y

Y coordinate

TYPE: T

to_int

Python
to_int() -> Vector2D[int]

Convert vector components to integers using truncation.

RETURNS DESCRIPTION
Vector2D[int]

Vector with integer components

magnitude

Python
magnitude() -> float

Calculate the magnitude (length) of the vector.

RETURNS DESCRIPTION
float

Magnitude of the vector

magnitude_squared

Python
magnitude_squared() -> Union[int, float]

Calculate the squared magnitude of the vector (more efficient than magnitude).

RETURNS DESCRIPTION
Union[int, float]

Squared magnitude of the vector

normalize

Python
normalize() -> Vector2D[float]

Return a normalized (unit) vector in the same direction.

RETURNS DESCRIPTION
Vector2D[float]

Normalized vector with magnitude 1, or zero vector if original magnitude is 0

distance_to

Python
distance_to(other: Vector2D[T]) -> float

Calculate the Euclidean distance to another vector.

PARAMETER DESCRIPTION
other

Target vector

TYPE: Vector2D[T]

RETURNS DESCRIPTION
float

Distance between the two vectors

copy

Python
copy() -> Vector2D[T]

Return a copy of the vector.

RETURNS DESCRIPTION
Vector2D[T]

A new Vector2D instance with the same components.

dot

Python
dot(other: Vector2D[T]) -> float

Calculate the dot product with another vector.

PARAMETER DESCRIPTION
other

The other vector

TYPE: Vector2D[T]

RETURNS DESCRIPTION
float

The dot product result

is_zero

Python
is_zero(tolerance: float = 1e-06) -> bool

Check if vector is approximately zero within tolerance.

PARAMETER DESCRIPTION
tolerance

Tolerance for zero check (default: 1e-6)

TYPE: float DEFAULT: 1e-06

RETURNS DESCRIPTION
bool

True if vector magnitude is below tolerance

lerp

Python
lerp(other: Vector2D[T], t: float) -> Vector2D[float]

Linear interpolation between this vector and another.

PARAMETER DESCRIPTION
other

Target vector

TYPE: Vector2D[T]

t

Interpolation factor (0.0 = this vector, 1.0 = other vector)

TYPE: float

RETURNS DESCRIPTION
Vector2D[float]

Interpolated vector

clamp_magnitude

Python
clamp_magnitude(max_magnitude: float) -> Vector2D[float]

Clamp vector magnitude to maximum value.

PARAMETER DESCRIPTION
max_magnitude

Maximum allowed magnitude

TYPE: float

RETURNS DESCRIPTION
Vector2D[float]

Vector with clamped magnitude

average staticmethod

Python
average(vectors: List[Vector2D[T]]) -> Vector2D[float]

Calculate the average of multiple vectors.

PARAMETER DESCRIPTION
vectors

List of vectors to average

TYPE: List[Vector2D[T]]

RETURNS DESCRIPTION
Vector2D[float]

Average vector, or zero vector if list is empty


Rotation

Python
Rotation(yaw: float, pitch: float)

Represents rotation with pitch and yaw angles in degrees.

Angles are normalized to the range [-180, 180] degrees.

ATTRIBUTE DESCRIPTION
yaw

Yaw angle in degrees, normalized to (-180, 180)

TYPE: float

pitch

Pitch angle in degrees, normalized to (-180, 180)

TYPE: float

to_radians

Python
to_radians() -> Tuple[float, float]

Convert angles to radians.

RETURNS DESCRIPTION
Tuple[float, float]

Tuple of (pitch_radians, yaw_radians)

to_degrees

Python
to_degrees() -> Tuple[float, float]

Get angles in degrees.

RETURNS DESCRIPTION
Tuple[float, float]

Tuple of (pitch_degrees, yaw_degrees)

from_radians classmethod

Python
from_radians(
    pitch_radians: float, yaw_radians: float
) -> Rotation

Create a Rotation from angles in radians.

PARAMETER DESCRIPTION
pitch_radians

Pitch angle in radians

TYPE: float

yaw_radians

Yaw angle in radians

TYPE: float

RETURNS DESCRIPTION
Rotation

New Rotation instance

copy

Python
copy() -> Rotation

Return a copy of the rotation.

RETURNS DESCRIPTION
Rotation

A new Rotation instance with the same yaw and pitch.