import mojoscale_math
The mojoscale_math module is a standalone MojoScale math library. It does not replace Berry's built-in ``math`` module; it adds MCU-friendly helpers for mapping sensor ranges, angle math, tolerances, small statistics, randomness, vectors, and quaternions. Constants: pi: Circle constant. e: Euler's number. tau: 2 * pi. inf: Positive infinity. nan: Not-a-number. DEG_TO_RAD: Multiply degrees by this value to get radians. RAD_TO_DEG: Multiply radians by this value to get degrees.
Quick example
import mojoscale_math as mm duty = mm.map(2048, 0, 4095, 0, 100, clamp=True) duty = mm.deadband(duty, 3) gravity = mm.vector3(0.02, -0.04, 9.81) tilt = gravity.angle_to(mm.vector3(0, 0, 1)) q = mm.quaternion_from_euler(0, tilt, 0) print(q.to_euler())
importmojoscale_math
Hardware-oriented math helpers for MojoScale Studio.
The mojoscale_math module is a standalone MojoScale math library. It does not replace Berry's built-in ``math`` module; it adds MCU-friendly helpers for mapping sensor ranges, angle math, tolerances, small statistics, randomness, vectors, and quaternions. Constants: pi: Circle constant. e: Euler's number. tau: 2 * pi. inf: Positive infinity. nan: Not-a-number. DEG_TO_RAD: Multiply degrees by this value to get radians. RAD_TO_DEG: Multiply radians by this value to get degrees.
mojoscale_math.abs(x: int) -> float
mojoscale_math.abs(x: int) -> floatReturn the absolute value.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Absolute value as float.
mojoscale_math.min(first: any, **numbers: any) -> float
mojoscale_math.min(first: any, **numbers: any) -> floatReturn the smallest positional value.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
first |
any |
positional or keyword | Yes | First numeric value. |
*numbers |
any |
extra positional | No | Additional numeric values. |
float Smallest value as float.
mojoscale_math.max(first: any, **numbers: any) -> float
mojoscale_math.max(first: any, **numbers: any) -> floatReturn the largest positional value.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
first |
any |
positional or keyword | Yes | First numeric value. |
*numbers |
any |
extra positional | No | Additional numeric values. |
float Largest value as float.
mojoscale_math.floor(x: int) -> float
mojoscale_math.floor(x: int) -> floatRound down to the nearest integer-valued float.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Floored value.
mojoscale_math.ceil(x: int) -> float
mojoscale_math.ceil(x: int) -> floatRound up to the nearest integer-valued float.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Ceiled value.
mojoscale_math.round(x: int) -> float
mojoscale_math.round(x: int) -> floatRound to the nearest integer-valued float.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Rounded value.
mojoscale_math.trunc(x: int) -> float
mojoscale_math.trunc(x: int) -> floatTruncate the fractional part.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Truncated value.
mojoscale_math.sqrt(x: int) -> int
mojoscale_math.sqrt(x: int) -> intReturn the square root.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
int Square root. Negative input follows the platform floating-point behavior.
mojoscale_math.pow(x: int, y: int) -> float
mojoscale_math.pow(x: int, y: int) -> floatRaise x to y.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Base value. |
y |
int |
positional or keyword | Yes | Exponent value. |
float x raised to y.
mojoscale_math.exp(x: int) -> float
mojoscale_math.exp(x: int) -> floatReturn e raised to x.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Exponential value.
mojoscale_math.log(x: int) -> float
mojoscale_math.log(x: int) -> floatReturn the natural logarithm.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Natural logarithm.
mojoscale_math.log10(x: int) -> float
mojoscale_math.log10(x: int) -> floatReturn the base-10 logarithm.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Base-10 logarithm.
mojoscale_math.log2(x: int) -> float
mojoscale_math.log2(x: int) -> floatReturn the base-2 logarithm.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Base-2 logarithm.
mojoscale_math.sin(x: int) -> float
mojoscale_math.sin(x: int) -> floatReturn sine of an angle in radians.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Angle in radians. |
float Sine value.
mojoscale_math.cos(x: int) -> float
mojoscale_math.cos(x: int) -> floatReturn cosine of an angle in radians.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Angle in radians. |
float Cosine value.
mojoscale_math.tan(x: int) -> float
mojoscale_math.tan(x: int) -> floatReturn tangent of an angle in radians.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Angle in radians. |
float Tangent value.
mojoscale_math.asin(x: int) -> float
mojoscale_math.asin(x: int) -> floatReturn arcsine in radians.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Angle in radians.
mojoscale_math.acos(x: int) -> float
mojoscale_math.acos(x: int) -> floatReturn arccosine in radians.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Angle in radians.
mojoscale_math.atan(x: int) -> float
mojoscale_math.atan(x: int) -> floatReturn arctangent in radians.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Angle in radians.
mojoscale_math.atan2(y: int, x: int) -> float
mojoscale_math.atan2(y: int, x: int) -> floatReturn arctangent of y/x in radians.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
y |
int |
positional or keyword | Yes | Y component. |
x |
int |
positional or keyword | Yes | X component. |
float Angle in radians.
mojoscale_math.sinh(x: int) -> float
mojoscale_math.sinh(x: int) -> floatReturn hyperbolic sine.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Hyperbolic sine.
mojoscale_math.cosh(x: int) -> float
mojoscale_math.cosh(x: int) -> floatReturn hyperbolic cosine.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Hyperbolic cosine.
mojoscale_math.tanh(x: int) -> float
mojoscale_math.tanh(x: int) -> floatReturn hyperbolic tangent.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
float Hyperbolic tangent.
mojoscale_math.isfinite(x: int) -> bool
mojoscale_math.isfinite(x: int) -> boolCheck whether a value is finite.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
bool True if x is neither infinity nor NaN.
mojoscale_math.isinf(x: int) -> bool
mojoscale_math.isinf(x: int) -> boolCheck whether a value is infinite.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
bool True if x is positive or negative infinity.
mojoscale_math.isnan(x: int) -> bool
mojoscale_math.isnan(x: int) -> boolCheck whether a value is NaN.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
bool True if x is NaN.
mojoscale_math.sign(x: int) -> int
mojoscale_math.sign(x: int) -> intReturn -1, 0, or 1 based on the value sign.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
int -1 for negative, 0 for zero, 1 for positive.
mojoscale_math.fmod(x: int, y: int) -> float
mojoscale_math.fmod(x: int, y: int) -> floatReturn floating-point remainder.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Dividend. |
y |
int |
positional or keyword | Yes | Divisor. |
float Remainder using C fmod behavior.
mojoscale_math.hypot(x: int, y: int) -> float
mojoscale_math.hypot(x: int, y: int) -> floatReturn sqrt(x*x + y*y).
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | X component. |
y |
int |
positional or keyword | Yes | Y component. |
float Euclidean hypotenuse.
mojoscale_math.clamp(value: any, minimum: any, maximum: any) -> float
mojoscale_math.clamp(value: any, minimum: any, maximum: any) -> floatClamp a value into a range.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
value |
any |
positional or keyword | Yes | Input value. |
minimum |
any |
positional or keyword | Yes | Lower bound. |
maximum |
any |
positional or keyword | Yes | Upper bound. |
float Clamped value.
mojoscale_math.map(value: any, in_min: any, in_max: any, out_min: any, out_max: any, clamp: bool = None) -> int
mojoscale_math.map(value: any, in_min: any, in_max: any, out_min: any, out_max: any, clamp: bool = None) -> intMap a value from one numeric range to another.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
value |
any |
positional or keyword | Yes | Input value. |
in_min |
any |
positional or keyword | Yes | Input range lower bound. |
in_max |
any |
positional or keyword | Yes | Input range upper bound. |
out_min |
any |
positional or keyword | Yes | Output range lower bound. |
out_max |
any |
positional or keyword | Yes | Output range upper bound. |
clamp |
bool |
positional or keyword | No | Optional bool. True clamps the interpolation amount to 0..1. |
int Mapped floating-point value.
mojoscale_math.lerp(a: any, b: any, amount: any) -> int
mojoscale_math.lerp(a: any, b: any, amount: any) -> intLinearly interpolate from a to b.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
a |
any |
positional or keyword | Yes | Start value. |
b |
any |
positional or keyword | Yes | End value. |
amount |
any |
positional or keyword | Yes | Interpolation amount. 0 returns a, 1 returns b. |
int Interpolated value.
mojoscale_math.inverse_lerp(a: any, b: any, value: any) -> int
mojoscale_math.inverse_lerp(a: any, b: any, value: any) -> intFind where value sits between a and b.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
a |
any |
positional or keyword | Yes | Start value. |
b |
any |
positional or keyword | Yes | End value. |
value |
any |
positional or keyword | Yes | Value to normalize. |
int Interpolation amount.
mojoscale_math.normalize(value: any, minimum: any, maximum: any) -> int
mojoscale_math.normalize(value: any, minimum: any, maximum: any) -> intNormalize a value inside a range.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
value |
any |
positional or keyword | Yes | Input value. |
minimum |
any |
positional or keyword | Yes | Range lower bound. |
maximum |
any |
positional or keyword | Yes | Range upper bound. |
int Normalized interpolation amount.
mojoscale_math.radians(degrees: any) -> float
mojoscale_math.radians(degrees: any) -> floatConvert degrees to radians.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
degrees |
any |
positional or keyword | Yes | Angle in degrees. |
float Angle in radians.
mojoscale_math.degrees(radians: any) -> float
mojoscale_math.degrees(radians: any) -> floatConvert radians to degrees.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
radians |
any |
positional or keyword | Yes | Angle in radians. |
float Angle in degrees.
mojoscale_math.wrap_angle(angle: float, unit: str = None) -> float
mojoscale_math.wrap_angle(angle: float, unit: str = None) -> floatWrap an angle to 0..360 or 0..2*pi.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
angle |
float |
positional or keyword | Yes | Angle value. |
unit |
str |
positional or keyword | No | Optional unit string. Use "degrees" or "radians". Defaults to "degrees". |
float Wrapped angle.
mojoscale_math.wrap_degrees(angle: float) -> float
mojoscale_math.wrap_degrees(angle: float) -> floatWrap degrees into the 0..360 range.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
angle |
float |
positional or keyword | Yes | Angle in degrees. |
float Wrapped angle in degrees.
mojoscale_math.wrap_radians(angle: float) -> float
mojoscale_math.wrap_radians(angle: float) -> floatWrap radians into the 0..2*pi range.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
angle |
float |
positional or keyword | Yes | Angle in radians. |
float Wrapped angle in radians.
mojoscale_math.angle_difference(a: any, b: any, unit: str = None) -> float
mojoscale_math.angle_difference(a: any, b: any, unit: str = None) -> floatShortest signed difference from angle a to b.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
a |
any |
positional or keyword | Yes | Start angle. |
b |
any |
positional or keyword | Yes | Target angle. |
unit |
str |
positional or keyword | No | Optional unit string. Use "degrees" or "radians". Defaults to "degrees". |
float Signed shortest difference.
mojoscale_math.angle_difference_degrees(a: any, b: any) -> float
mojoscale_math.angle_difference_degrees(a: any, b: any) -> floatShortest signed difference in degrees.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
a |
any |
positional or keyword | Yes | Start angle in degrees. |
b |
any |
positional or keyword | Yes | Target angle in degrees. |
float Signed shortest difference in degrees.
mojoscale_math.angle_difference_radians(a: any, b: any) -> float
mojoscale_math.angle_difference_radians(a: any, b: any) -> floatShortest signed difference in radians.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
a |
any |
positional or keyword | Yes | Start angle in radians. |
b |
any |
positional or keyword | Yes | Target angle in radians. |
float Signed shortest difference in radians.
mojoscale_math.lerp_angle(a: any, b: any, amount: any, unit: str = None) -> int
mojoscale_math.lerp_angle(a: any, b: any, amount: any, unit: str = None) -> intInterpolate along the shortest angle path.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
a |
any |
positional or keyword | Yes | Start angle. |
b |
any |
positional or keyword | Yes | Target angle. |
amount |
any |
positional or keyword | Yes | Interpolation amount. |
unit |
str |
positional or keyword | No | Optional unit string. Use "degrees" or "radians". Defaults to "degrees". |
int Interpolated wrapped angle.
mojoscale_math.lerp_angle_degrees(a: any, b: any, amount: any) -> int
mojoscale_math.lerp_angle_degrees(a: any, b: any, amount: any) -> intInterpolate degrees along the shortest angle path.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
a |
any |
positional or keyword | Yes | Start angle in degrees. |
b |
any |
positional or keyword | Yes | Target angle in degrees. |
amount |
any |
positional or keyword | Yes | Interpolation amount. |
int Interpolated wrapped degrees.
mojoscale_math.lerp_angle_radians(a: any, b: any, amount: any) -> int
mojoscale_math.lerp_angle_radians(a: any, b: any, amount: any) -> intInterpolate radians along the shortest angle path.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
a |
any |
positional or keyword | Yes | Start angle in radians. |
b |
any |
positional or keyword | Yes | Target angle in radians. |
amount |
any |
positional or keyword | Yes | Interpolation amount. |
int Interpolated wrapped radians.
mojoscale_math.isclose(a: any, b: any, rel_tol: any = None, abs_tol: any = None) -> bool
mojoscale_math.isclose(a: any, b: any, rel_tol: any = None, abs_tol: any = None) -> boolCompare floats with relative and absolute tolerance.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
a |
any |
positional or keyword | Yes | First value. |
b |
any |
positional or keyword | Yes | Second value. |
rel_tol |
any |
positional or keyword | No | Optional relative tolerance. Defaults to 1e-6. |
abs_tol |
any |
positional or keyword | No | Optional absolute tolerance. Defaults to 1e-9. |
bool True when the values are close.
mojoscale_math.near_zero(x: int, tolerance: any = None) -> bool
mojoscale_math.near_zero(x: int, tolerance: any = None) -> boolCheck whether a value is close to zero.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | Numeric value. |
tolerance |
any |
positional or keyword | No | Optional absolute tolerance. Defaults to 1e-6. |
bool True when abs(x) <= tolerance.
mojoscale_math.deadband(value: any, threshold: float) -> float
mojoscale_math.deadband(value: any, threshold: float) -> floatSuppress small values around zero.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
value |
any |
positional or keyword | Yes | Input value. |
threshold |
float |
positional or keyword | Yes | Deadband threshold. |
float 0 when abs(value) < threshold, otherwise value.
mojoscale_math.smoothstep(edge0: any, edge1: any, value: any) -> float
mojoscale_math.smoothstep(edge0: any, edge1: any, value: any) -> floatSmoothly interpolate from 0 to 1 between two edges.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
edge0 |
any |
positional or keyword | Yes | Lower edge. |
edge1 |
any |
positional or keyword | Yes | Upper edge. |
value |
any |
positional or keyword | Yes | Input value. |
float Smoothstep value from 0 to 1.
mojoscale_math.move_towards(current: float, target: any, maximum_change: any) -> float
mojoscale_math.move_towards(current: float, target: any, maximum_change: any) -> floatMove a value toward a target by no more than maximum_change.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
current |
float |
positional or keyword | Yes | Current value. |
target |
any |
positional or keyword | Yes | Target value. |
maximum_change |
any |
positional or keyword | Yes | Maximum absolute change. |
float Updated value.
mojoscale_math.sum(values: list) -> float
mojoscale_math.sum(values: list) -> floatReturn the sum of numeric list values.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
values |
list |
positional or keyword | Yes | List of numbers. |
float Numeric sum.
mojoscale_math.mean(values: list) -> float
mojoscale_math.mean(values: list) -> floatReturn the mean of numeric list values.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
values |
list |
positional or keyword | Yes | List of numbers. |
float Mean value.
mojoscale_math.median(values: list) -> float
mojoscale_math.median(values: list) -> floatReturn the median of numeric list values.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
values |
list |
positional or keyword | Yes | List of numbers. |
float Median value.
mojoscale_math.variance(values: list, sample: bool = None) -> float
mojoscale_math.variance(values: list, sample: bool = None) -> floatReturn population or sample variance.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
values |
list |
positional or keyword | Yes | List of numbers. |
sample |
bool |
positional or keyword | No | Optional bool. True uses sample variance, False uses population variance. |
float Variance.
mojoscale_math.stddev(values: list, sample: bool = None) -> float
mojoscale_math.stddev(values: list, sample: bool = None) -> floatReturn population or sample standard deviation.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
values |
list |
positional or keyword | Yes | List of numbers. |
sample |
bool |
positional or keyword | No | Optional bool. True uses sample standard deviation. |
float Standard deviation.
mojoscale_math.minimum(values: list) -> list
mojoscale_math.minimum(values: list) -> listReturn the smallest value in a numeric list.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
values |
list |
positional or keyword | Yes | List of numbers. |
list Minimum list value.
mojoscale_math.maximum(values: list) -> list
mojoscale_math.maximum(values: list) -> listReturn the largest value in a numeric list.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
values |
list |
positional or keyword | Yes | List of numbers. |
list Maximum list value.
mojoscale_math.range(values: list) -> float
mojoscale_math.range(values: list) -> floatReturn maximum(values) - minimum(values).
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
values |
list |
positional or keyword | Yes | List of numbers. |
float Numeric range.
mojoscale_math.rms(values: list) -> float
mojoscale_math.rms(values: list) -> floatReturn root-mean-square of numeric list values.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
values |
list |
positional or keyword | Yes | List of numbers. |
float RMS value.
mojoscale_math.seed(value: any) -> bool
mojoscale_math.seed(value: any) -> boolSeed the pseudo-random generator.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
value |
any |
positional or keyword | Yes | Integer seed. |
bool True.
mojoscale_math.random() -> float
mojoscale_math.random() -> floatReturn pseudo-random float from 0.0 inclusive to 1.0 exclusive.
float Random float. Not cryptographically secure.
mojoscale_math.randint(minimum: any, maximum: any) -> int
mojoscale_math.randint(minimum: any, maximum: any) -> intReturn pseudo-random integer in an inclusive range.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
minimum |
any |
positional or keyword | Yes | Inclusive lower bound. |
maximum |
any |
positional or keyword | Yes | Inclusive upper bound. |
int Random integer. Not cryptographically secure.
mojoscale_math.uniform(minimum: any, maximum: any) -> float
mojoscale_math.uniform(minimum: any, maximum: any) -> floatReturn pseudo-random float in a range.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
minimum |
any |
positional or keyword | Yes | Lower bound. |
maximum |
any |
positional or keyword | Yes | Upper bound. |
float Random float. Not cryptographically secure.
mojoscale_math.choice(values: list) -> list
mojoscale_math.choice(values: list) -> listReturn one pseudo-random value from a list.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
values |
list |
positional or keyword | Yes | Non-empty list. |
list One list element.
mojoscale_math.vector2(x: int, y: int) -> vector2
mojoscale_math.vector2(x: int, y: int) -> vector2Create a 2D vector.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | X component. |
y |
int |
positional or keyword | Yes | Y component. |
vector2 vector2 object.
mojoscale_math.vector2().length() -> float
mojoscale_math.vector2().length() -> floatReturn vector magnitude.
mojoscale_math.vector2().length_squared() -> float
mojoscale_math.vector2().length_squared() -> floatReturn squared magnitude.
mojoscale_math.vector2().normalized() -> vector2
mojoscale_math.vector2().normalized() -> vector2Return a unit vector.
mojoscale_math.vector2().dot(other) -> float
mojoscale_math.vector2().dot(other) -> floatDot product with another vector2.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
other |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector2().distance_to(other) -> float
mojoscale_math.vector2().distance_to(other) -> floatDistance to another vector2.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
other |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector2().angle_to(other) -> float
mojoscale_math.vector2().angle_to(other) -> floatAngle to another vector2 in radians.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
other |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector2().add(other) -> vector2
mojoscale_math.vector2().add(other) -> vector2Component-wise addition.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
other |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector2().sub(other) -> vector2
mojoscale_math.vector2().sub(other) -> vector2Component-wise subtraction.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
other |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector2().scale(value) -> vector2
mojoscale_math.vector2().scale(value) -> vector2Multiply by scalar.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
value |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector2().div(value) -> vector2
mojoscale_math.vector2().div(value) -> vector2Divide by scalar.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
value |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector2().to_map() -> dict: Return {"x": x, "y"
mojoscale_math.vector2().to_map() -> dict: Return {"x": x, "y"y}.
mojoscale_math.vector3(x: int, y: int, z: any) -> vector3
mojoscale_math.vector3(x: int, y: int, z: any) -> vector3Create a 3D vector.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
x |
int |
positional or keyword | Yes | X component. |
y |
int |
positional or keyword | Yes | Y component. |
z |
any |
positional or keyword | Yes | Z component. |
vector3 vector3 object.
mojoscale_math.vector3().length() -> float
mojoscale_math.vector3().length() -> floatReturn vector magnitude.
mojoscale_math.vector3().length_squared() -> float
mojoscale_math.vector3().length_squared() -> floatReturn squared magnitude.
mojoscale_math.vector3().normalized() -> vector3
mojoscale_math.vector3().normalized() -> vector3Return a unit vector.
mojoscale_math.vector3().dot(other) -> float
mojoscale_math.vector3().dot(other) -> floatDot product with another vector3.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
other |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector3().cross(other) -> vector3
mojoscale_math.vector3().cross(other) -> vector3Cross product with another vector3.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
other |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector3().distance_to(other) -> float
mojoscale_math.vector3().distance_to(other) -> floatDistance to another vector3.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
other |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector3().angle_to(other) -> float
mojoscale_math.vector3().angle_to(other) -> floatAngle to another vector3 in radians.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
other |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector3().add(other) -> vector3
mojoscale_math.vector3().add(other) -> vector3Component-wise addition.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
other |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector3().sub(other) -> vector3
mojoscale_math.vector3().sub(other) -> vector3Component-wise subtraction.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
other |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector3().scale(value) -> vector3
mojoscale_math.vector3().scale(value) -> vector3Multiply by scalar.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
value |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector3().div(value) -> vector3
mojoscale_math.vector3().div(value) -> vector3Divide by scalar.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
value |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.vector3().to_map() -> dict: Return {"x": x, "y": y, "z"
mojoscale_math.vector3().to_map() -> dict: Return {"x": x, "y": y, "z"z}.
mojoscale_math.quaternion(w: any, x: int, y: int, z: any) -> quaternion
mojoscale_math.quaternion(w: any, x: int, y: int, z: any) -> quaternionCreate a quaternion using w, x, y, z ordering.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
w |
any |
positional or keyword | Yes | Real component. |
x |
int |
positional or keyword | Yes | X imaginary component. |
y |
int |
positional or keyword | Yes | Y imaginary component. |
z |
any |
positional or keyword | Yes | Z imaginary component. |
quaternion quaternion object.
mojoscale_math.quaternion().normalized() -> quaternion
mojoscale_math.quaternion().normalized() -> quaternionReturn a unit quaternion.
mojoscale_math.quaternion().conjugate() -> quaternion
mojoscale_math.quaternion().conjugate() -> quaternionReturn the conjugate.
mojoscale_math.quaternion().inverse() -> quaternion
mojoscale_math.quaternion().inverse() -> quaternionReturn the inverse.
mojoscale_math.quaternion().multiply(other) -> quaternion
mojoscale_math.quaternion().multiply(other) -> quaternionHamilton product with another quaternion.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
other |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.quaternion().rotate(vector) -> vector3
mojoscale_math.quaternion().rotate(vector) -> vector3Rotate a vector3 by this quaternion.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
vector |
any |
positional or keyword | Yes | Required value. |
mojoscale_math.quaternion().to_euler() -> dict
mojoscale_math.quaternion().to_euler() -> dictReturn roll, pitch, and yaw in radians.
mojoscale_math.quaternion().to_matrix() -> list
mojoscale_math.quaternion().to_matrix() -> listReturn a 3x3 rotation matrix as nested lists.
mojoscale_math.quaternion().to_map() -> dict: Return {"w": w, "x": x, "y": y, "z"
mojoscale_math.quaternion().to_map() -> dict: Return {"w": w, "x": x, "y": y, "z"z}.
mojoscale_math.quaternion_from_euler(roll: any, pitch: any, yaw: any) -> quaternion
mojoscale_math.quaternion_from_euler(roll: any, pitch: any, yaw: any) -> quaternionCreate a quaternion from roll, pitch, yaw radians.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
roll |
any |
positional or keyword | Yes | Roll angle in radians. |
pitch |
any |
positional or keyword | Yes | Pitch angle in radians. |
yaw |
any |
positional or keyword | Yes | Yaw angle in radians. |
quaternion quaternion object.
mojoscale_math.quaternion_from_axis_angle(axis: any, angle: float) -> quaternion
mojoscale_math.quaternion_from_axis_angle(axis: any, angle: float) -> quaternionCreate a quaternion from an axis vector and angle.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
axis |
any |
positional or keyword | Yes | vector3 rotation axis. |
angle |
float |
positional or keyword | Yes | Rotation angle in radians. |
quaternion quaternion object.
mojoscale_math.quaternion_slerp(a: any, b: any, amount: any) -> quaternion
mojoscale_math.quaternion_slerp(a: any, b: any, amount: any) -> quaternionSpherically interpolate between two quaternions.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
a |
any |
positional or keyword | Yes | Start quaternion. |
b |
any |
positional or keyword | Yes | End quaternion. |
amount |
any |
positional or keyword | Yes | Interpolation amount from 0 to 1. |
quaternion quaternion object.