feat: add a 3D middle point function

This commit is contained in:
Kazhnuz 2020-11-25 13:02:11 +01:00
parent 5837fd8b51
commit 124a228d3b

View file

@ -87,7 +87,6 @@ function Math.pointDistance(x1, y1, x2, y2)
vecy = math.max(y1, y2) - math.min(y1, y2)
return math.sqrt(vecx^2 + vecy^2)
end
function Math.pointDirection(x1,y1,x2,y2)
@ -99,6 +98,34 @@ function Math.pointDirection(x1,y1,x2,y2)
return angle
end
-- 3D MATH FUNCTIONS
-- Basic math calculations
function Math.getMiddlePoint3D(x1, y1, z1, x2, y2, z2)
local newx, newy, newz, vecx, vecy, vecz
vecx = math.max(x1, x2) - math.min(x1, x2)
vecy = math.max(y1, y2) - math.min(y1, y2)
vecz = math.max(z1, z2) - math.min(z1, z2)
newx = math.min(x1, x2) + (vecx / 2)
newy = math.min(y1, y2) + (vecy / 2)
newz = math.min(z1, z2) + (vecz / 2)
return newx, newy, newz
end
function Math.pointDistance3D(x1, y1, z1, x2, y2, z2)
local vecx, vecy, vecz
vecx = math.max(x1, x2) - math.min(x1, x2)
vecy = math.max(y1, y2) - math.min(y1, y2)
vecz = math.max(z1, z2) - math.min(z1, z2)
return math.sqrt(vecx^2 + vecy^2 + vecz^2)
end
-- STRING FUNCTIONS
-- Transform into string numbers