math
pykraken.math Math related functions
At a glance
8 membersReference
PYTHON APIangle_between
functionCalculate the angle between two vectors.
Args
- a (
Vec2) — The first vector. - b (
Vec2) — The second vector.
Returns
- float — The angle between the vectors in radians [0, π].
clamp(value: float, min_val: float, max_val: float) -> floatOverloaded function.
clamp(vec: Vec2, min_vec: Vec2, max_vec: Vec2) -> Vec2
Clamp a vector between two boundary vectors.
Args
- vec (
Vec2) — The vector to clamp. - min_vec (
Vec2) — The minimum boundary vector. - max_vec (
Vec2) — The maximum boundary vector.
Returns
- Vec2 — A new vector with components clamped between min and max.
clamp(value: float, min_val: float, max_val: float) -> float
Clamp a value between two boundaries.
Args
- value (
float) — The value to clamp. - min_val (
float) — The minimum boundary. - max_val (
float) — The maximum boundary.
Returns
- float — The clamped value.
cross
functionCalculate the 2D cross product of two vectors. (a.x * b.y - a.y * b.x)
Args
- a (
Vec2) — The first vector. - b (
Vec2) — The second vector.
Returns
- float — The 2D cross product.
dot
functionCalculate the dot product of two vectors.
Args
- a (
Vec2) — The first vector. - b (
Vec2) — The second vector.
Returns
- float — The dot product (a.x * b.x + a.y * b.y).
from_polar
functionfrom_polar(angle: float, radius: float) -> Vec2Convert polar coordinates to a Cartesian vector.
Args
- angle (
float) — The angle in radians. - radius (
float) — The radius/distance from origin.
Returns
- Vec2 — The equivalent Cartesian vector.
Overloaded function.
lerp(a: Vec2, b: Vec2, t: float) -> Vec2
Linearly interpolate between two Vec2s.
Args
- a (
Vec2) — The start vector. - b (
Vec2) — The end vector. - t (
float) — The interpolation factor [0.0, 1.0].
Returns
- Vec2 — The interpolated vector.
lerp(a: float, b: float, t: float) -> float
Linearly interpolate between two values.
Args
- a (
float) — The start value. - b (
float) — The end value. - t (
float) — The interpolation factor [0.0, 1.0].
Returns
- float — The interpolated value.
move_toward
functionmove_toward(current: float, target: float, delta: float) -> floatMove a value toward a target by a maximum delta.
Args
- current (
float) — The current value. - target (
float) — The target value. - delta (
float) — The maximum amount to move toward the target.
Returns
- float — The new value after moving toward the target.
remap
functionremap(in_min: float, in_max: float, out_min: float, out_max: float, value: float) -> floatRemap a value from one range to another.
Args
- in_min (
float) — Input range minimum. - in_max (
float) — Input range maximum. - out_min (
float) — Output range minimum. - out_max (
float) — Output range maximum. - value (
float) — The value to remap.
Returns
- float — The remapped value in the output range.
Raises
- ValueError — If in_min equals in_max.