Sandbox: Lua: Math - ov-studio/Vital.sandbox GitHub Wiki

━ What's the Objective?

Lua provides built in math module by default, however it lacks certain special vendors & classes that are essentially required for most of the generic cases such as Quat, Matrix etc; thus, the extension!

━ Modules

━ APIs

ℹ️ Note:

Our extensions are written with backwards compatibility in mind; Expect your previous code to work as usual! However we recommend upgrading to newer syntax.


━ math.round() (Shared)

@Objective: Rounds a floating point value by specified decimals.
local float: result = math.round(
  float: value,
  int: decimals --(Optional) By default its 0 if left unspecified
)

━ math.percent() (Shared)

@Objective: Retrieves specified percentage of the value.
local float: result = math.percent(
  float: value,
  float: percent
)

━ math.findDistance2D() (Shared)

@Objective: Retrieves distance b/w two 2D-Points.
local float: result = math.findDistance2D(
  float: x1,
  float: y1,
  float: x2,
  float: y2
)

━ math.findDistance3D() (Shared)

@Objective: Retrieves distance b/w two 3D-Points.
local float: result = math.findDistance3D(
  float: x1,
  float: y1,
  float: z1
  float: x2,
  float: y2,
  float: z2
)

━ math.findRotation2D() (Shared)

@Objective: Generates nearest possible rotation b/w two 2D-Points.
local float: result = math.findRotation2D(
  float: x1,
  float: y1,
  float: x2,
  float: y2
)

━ math.findPointByRotation2D() (Shared)

@Objective: Generates new coords of an existing 2D-Point after rotating it by specified distance & rotation angle.
local float: result = math.findPointByRotation2D(
  float: x,
  float: y,
  float: distance,
  float: rotation
)