Math
Math related functions
Angle Between
angle_between(a: Vec2, b: Vec2) → floatCalculate the angle between two vectors.
Args
a: The first vector.b: The second vector.
Returns
float : The angle between the vectors in radians [0, π].
Clamp
clamp(vec: Vec2, min_vec: Vec2, max_vec: Vec2) → Vec2Clamp a vector between two boundary vectors.
Args
vec: The vector to clamp.min_vec: The minimum boundary vector.max_vec: The maximum boundary vector.
Returns
Vec2 : A new vector with components clamped between min and max.
clamp(
value: SupportsFloat,
min_val: SupportsFloat,
max_val: SupportsFloat
) → floatClamp a value between two boundaries.
Args
value: The value to clamp.min_val: The minimum boundary.max_val: The maximum boundary.
Returns
float : The clamped value.
Cross
cross(a: Vec2, b: Vec2) → floatCalculate the 2D cross product of two vectors.
Args
a: The first vector.b: The second vector.
Returns
float : The 2D cross product (a.x * b.y - a.y * b.x).
Dot
dot(a: Vec2, b: Vec2) → floatCalculate the dot product of two vectors.
Args
a: The first vector.b: The second vector.
Returns
float : The dot product (a.x * b.x + a.y * b.y).
From Polar
from_polar(
angle: SupportsFloat,
radius: SupportsFloat
) → Vec2Convert polar coordinates to a Cartesian vector.
Args
angle: The angle in radians.radius: The radius/distance from origin.
Returns
Vec2 : The equivalent Cartesian vector.
Lerp
lerp(a: Vec2, b: Vec2, t: SupportsFloat) → Vec2Linearly interpolate between two Vec2s.
Args
a: The start vector.b: The end vector.t: The interpolation factor [0.0, 1.0].
Returns
Vec2 : The interpolated vector.
lerp(
a: SupportsFloat,
b: SupportsFloat,
t: SupportsFloat
) → floatLinearly interpolate between two values.
Args
a: The start value.b: The end value.t: The interpolation factor [0.0, 1.0].
Returns
float : The interpolated value.
Remap
remap(
in_min: SupportsFloat,
in_max: SupportsFloat,
out_min: SupportsFloat,
out_max: SupportsFloat,
value: SupportsFloat
) → floatRemap a value from one range to another.
Args
in_min: Input range minimum.in_max: Input range maximum.out_min: Output range minimum.out_max: Output range maximum.value: The value to remap.
Returns
float : The remapped value in the output range.
Raises
ValueError: If in_min equals in_max.
To Deg
to_deg(radians: SupportsFloat) → floatConvert radians to degrees.
Args
radians: The angle in radians.
Returns
float : The angle in degrees.
To Rad
to_rad(degrees: SupportsFloat) → floatConvert degrees to radians.
Args
degrees: The angle in degrees.
Returns
float : The angle in radians.