Math
Functions for mathematical operations.
Scale To Length
scale_to_length(vec: Vec2, length: float) → Vec2
Scale a vector to a specific length.
Parameters
vec
: The vector to scale.length
: The desired length of the vector.
Returns
Vec2
: The scaled vector.
From Polar
from_polar(angle: float, radius: float) → Vec2
Create a vector from polar coordinates.
Parameters
angle
: The angle in radians.radius
: The radius or length of the vector.
Returns
Vec2
: The created vector.
from_polar(polar: PolarCoordinate) → Vec2
Create a vector from a polar coordinate object.
Parameters
polar
: The polar coordinate object.
Returns
Vec2
: The created vector.
Normalize
normalize(vec: Vec2) → Vec2
Normalize a vector to unit length.
Parameters
vec
: The vector to normalize.
Returns
Vec2
: The normalized vector.
Clamp Vec
clamp_vec(vec: Vec2, min: Vec2, max: Vec2) → Vec2
Clamp a vector to a specified range.
Parameters
vec
: The vector to clamp.min
: The minimum allowed values for each component.max
: The maximum allowed values for each component.
Returns
Vec2
: The clamped vector.
Lerp
lerp(a: Vec2, b: Vec2, t: float) → Vec2
Linearly interpolate between two vectors.
Parameters
a
: The starting vector.b
: The ending vector.t
: The interpolation factor (between 0 and 1).
Returns
Vec2
: The interpolated vector.
lerp(a: float, b: float, t: float) → float
Linearly interpolate between two floats.
Parameters
a
: The starting float.b
: The ending float.t
: The interpolation factor (between 0 and 1).
Returns
float
: The interpolated float.
Remap
remap(in_min: float, in_max: float, out_min: float, out_max: float, value: float) → float
Remap a value from one range to another.
Parameters
in_min
: The minimum of the input range.in_max
: The maximum of the input range.out_min
: The minimum of the output range.out_max
: The maximum of the output range.value
: The value to remap.
Returns
float
: The remapped value.
To Deg
to_deg(rad: float) → float
Convert radians to degrees.
Parameters
rad
: The angle in radians.
Returns
float
: The angle in degrees.
To Rad
to_rad(deg: float) → float
Convert degrees to radians.
Parameters
deg
: The angle in degrees.
Returns
float
: The angle in radians.
Dot
dot(a: Vec2, b: Vec2) → float
Calculate the dot product of two vectors.
Parameters
a
: The LHS vector.b
: The RHS vector.
Returns
float
: The dot product of the two vectors.
Cross
cross(a: Vec2, b: Vec2) → float
Calculate the cross product of two vectors.
Parameters
a
: The LHS vector.b
: The RHS vector.
Returns
float
: The cross product of the two vectors.
Angle Between
angle_between(a: Vec2, b: Vec2) → float
Calculate the angle between two vectors in radians.
Parameters
a
: The LHS vector.b
: The RHS vector.
Returns
float
: The angle between the two vectors in radians.