Math

Math related functions


Angle Between

angle_between(a: Vec2, b: Vec2) float

Calculate 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) Vec2

Clamp 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
) float

Clamp 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) float

Calculate 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) float

Calculate 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
) Vec2

Convert 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) Vec2

Linearly 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
) float

Linearly 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
) float

Remap 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) float

Convert radians to degrees.

Args

  • radians : The angle in radians.

Returns

float : The angle in degrees.

To Rad

to_rad(degrees: SupportsFloat) float

Convert degrees to radians.

Args

  • degrees : The angle in degrees.

Returns

float : The angle in radians.