Math
Functions for mathematical operations.
Scale To Length
scale_to_length(vec: Vec2, length: float) → Vec2Scale 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) → Vec2Create 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) → Vec2Create a vector from a polar coordinate object.
Parameters
polar: The polar coordinate object.
Returns
Vec2 : The created vector.
Normalize
normalize(vec: Vec2) → Vec2Normalize a vector to unit length. Will return a zero vector if the input vector has zero length.
Parameters
vec: The vector to normalize.
Returns
Vec2 : The normalized vector.
Clamp
clamp(vec: Vec2, min: Vec2, max: Vec2) → Vec2Clamp 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.
clamp(value: float, min: float, max: float) → floatClamp a value to a specified range.
Parameters
value: The value to clamp.min: The minimum allowed value.max: The maximum allowed value.
Returns
float : The clamped value.
Lerp
lerp(a: Vec2, b: Vec2, t: float) → Vec2Linearly 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) → floatLinearly 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) → floatRemap 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) → floatConvert radians to degrees.
Parameters
rad: The angle in radians.
Returns
float : The angle in degrees.
To Rad
to_rad(deg: float) → floatConvert degrees to radians.
Parameters
deg: The angle in degrees.
Returns
float : The angle in radians.
Dot
dot(a: Vec2, b: Vec2) → floatCalculate 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) → floatCalculate the cross product of two vectors.
Parameters
a: The LHS vector.b: The RHS vector.
Returns
float : The cross product of the two vectors.
Rotate
rotate(vec: Vec2, angle: float) → Vec2Rotate a vector by a given angle.
Parameters
vec: The vector to rotate.angle: The angle to rotate the vector by, in radians.
Returns
Vec2 : The rotated vector.
Angle Between
angle_between(a: Vec2, b: Vec2) → floatCalculate 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.