Documentation
  • 👋Introduction
  • 📚Guides
    • Useful Links
  • 🆓boii_utils
    • Installation
    • Configuration
    • Modules
    • API
      • Callbacks
      • Characters
      • Commands
      • Cooldowns
      • Debugging
      • Entities
      • Environment
      • Framework Bridge
      • Geometry
      • Items
      • Keys
      • Licences
      • Maths
      • Methods
      • Player
      • Requests
      • Strings
      • Tables
      • Timestamps
      • UI Bridges
      • Vehicles
      • Version
      • XP
      • UI Elements
Powered by GitBook
On this page
  • Accessing the Module
  • Shared
  • round(number, decimals)
  • calculate_distance(start_coords, end_coords)
  • clamp(val, lower, upper)
  • lerp(a, b, t)
  • factorial(n)
  • deg_to_rad(deg)
  • rad_to_deg(rad)
  • circle_circumference(radius)
  • circle_area(radius)
  • triangle_area(p1, p2, p3)
  • mean(numbers)
  • median(numbers)
  • mode(numbers)
  • standard_deviation(numbers)
  • linear_regression(points)
  1. boii_utils
  2. API

Maths

Provides mathematical utility functions not covered by Lua's built-in math library.


Accessing the Module

local MATHS <const> = exports.boii_utils:get("modules.maths")

Shared

round(number, decimals)

Rounds a number to a specified number of decimal places.

Parameters

Name
Type
Description

number

number

The number to round

decimals

number

Number of decimal places to round to

Example

local result = MATHS.round(3.14159, 2) -- 3.14

calculate_distance(start_coords, end_coords)

Calculates the 3D distance between two points.

Parameters

Name
Type
Description

start_coords

table

Start point {x, y, z}

end_coords

table

End point {x, y, z}

Example

local dist = MATHS.calculate_distance({x=0,y=0,z=0}, {x=3,y=4,z=0}) -- 5.0

clamp(val, lower, upper)

Clamps a number within a given range.

Parameters

Name
Type
Description

val

number

Value to clamp

lower

number

Minimum value

upper

number

Maximum value

Example

local result = MATHS.clamp(15, 0, 10) -- 10

lerp(a, b, t)

Performs linear interpolation between two numbers.

Parameters

Name
Type
Description

a

number

Start value

b

number

End value

t

number

Interpolation factor (0.0-1.0)

Example

local result = MATHS.lerp(0, 100, 0.5) -- 50

factorial(n)

Calculates the factorial of a number.

Parameters

Name
Type
Description

n

number

Number to factorial

Example

local fact = MATHS.factorial(5) -- 120

deg_to_rad(deg)

Converts degrees to radians.

Parameters

Name
Type
Description

deg

number

Angle in degrees

Example

local rad = MATHS.deg_to_rad(180) -- 3.1415...

rad_to_deg(rad)

Converts radians to degrees.

Parameters

Name
Type
Description

rad

number

Angle in radians

Example

local deg = MATHS.rad_to_deg(math.pi) -- 180

circle_circumference(radius)

Returns circumference of a circle.

Parameters

Name
Type
Description

radius

number

Radius of circle

Example

local circ = MATHS.circle_circumference(10) -- 62.83...

circle_area(radius)

Returns area of a circle.

Parameters

Name
Type
Description

radius

number

Radius of circle

Example

local area = MATHS.circle_area(5) -- 78.539...

triangle_area(p1, p2, p3)

Calculates area of triangle from 2D points.

Parameters

Name
Type
Description

p1

table

Point {x, y}

p2

table

Point {x, y}

p3

table

Point {x, y}

Example

local area = MATHS.triangle_area(p1, p2, p3)

mean(numbers)

Returns average of number list.

Parameters

Name
Type
Description

numbers

table

List of numbers

Example

local avg = MATHS.mean({1,2,3,4,5}) -- 3

median(numbers)

Returns median of list.

Parameters

Name
Type
Description

numbers

table

List of numbers

Example

local m = MATHS.median({5, 2, 1, 4, 3}) -- 3

mode(numbers)

Returns most frequent number.

Parameters

Name
Type
Description

numbers

table

List of numbers

Example

local m = MATHS.mode({1, 2, 2, 3, 4}) -- 2

standard_deviation(numbers)

Returns standard deviation.

Parameters

Name
Type
Description

numbers

table

List of numbers

Example

local std = MATHS.standard_deviation({1,2,3,4,5})

linear_regression(points)

Returns slope + intercept for set of 2D points.

Parameters

Name
Type
Description

points

table

List of {x, y} points

Example

local result = MATHS.linear_regression({{x=1,y=2},{x=2,y=4},{x=3,y=6}})
print(result.slope, result.intercept)
PreviousLicencesNextMethods

Last updated 1 month ago

🆓