Maths
Provides mathematical utility functions not covered by Lua's built-in math library.
Accessing the Module
Shared
round(number, decimals)
Rounds a number to a specified number of decimal places.
Parameters
number
number
The number to round
decimals
number
Number of decimal places to round to
Example
calculate_distance(start_coords, end_coords)
Calculates the 3D distance between two points.
Parameters
start_coords
table
Start point {x, y, z}
end_coords
table
End point {x, y, z}
Example
clamp(val, lower, upper)
Clamps a number within a given range.
Parameters
val
number
Value to clamp
lower
number
Minimum value
upper
number
Maximum value
Example
lerp(a, b, t)
Performs linear interpolation between two numbers.
Parameters
a
number
Start value
b
number
End value
t
number
Interpolation factor (0.0-1.0)
Example
factorial(n)
Calculates the factorial of a number.
Parameters
n
number
Number to factorial
Example
deg_to_rad(deg)
Converts degrees to radians.
Parameters
deg
number
Angle in degrees
Example
rad_to_deg(rad)
Converts radians to degrees.
Parameters
rad
number
Angle in radians
Example
circle_circumference(radius)
Returns circumference of a circle.
Parameters
radius
number
Radius of circle
Example
circle_area(radius)
Returns area of a circle.
Parameters
radius
number
Radius of circle
Example
triangle_area(p1, p2, p3)
Calculates area of triangle from 2D points.
Parameters
p1
table
Point {x, y}
p2
table
Point {x, y}
p3
table
Point {x, y}
Example
mean(numbers)
Returns average of number list.
Parameters
numbers
table
List of numbers
Example
median(numbers)
Returns median of list.
Parameters
numbers
table
List of numbers
Example
mode(numbers)
Returns most frequent number.
Parameters
numbers
table
List of numbers
Example
standard_deviation(numbers)
Returns standard deviation.
Parameters
numbers
table
List of numbers
Example
linear_regression(points)
Returns slope + intercept for set of 2D points.
Parameters
points
table
List of {x, y}
points
Example
Last updated