Standard rounding function; rounds a value up or down to its nearest whole value.
local roundedValue = math.round(1.5); -- roundedValue should round up to 2.0
Standard distance function; it accepts two points and returns their computed distance.
There are two variations of this function: one for 2D distance, and one for 3D. If you supply 4 parameters (x1, y1, x2, y2), the result will be the distance between the 2D points. If 6 parameters are given (x1, y1, z1, x2, y2, z2) the result will be the distance between the 3D points.
local dist2d = math.distance(0, 0, 1, 1); -- ~1.414 from (0,0) to (1,1)
local dist3d = math.distance(0, 0, 0, 1, 1, 1); -- ~1.732 from (0,0,0) to (1,1,1)
Page last updated at 2018-10-03 01:36:11
Copyright 2023