Mothback/code/math.lua

28 lines
503 B
Lua

function math.sign(x)
if x<0 then
return -1
elseif x>0 then
return 1
else
return 0
end
end
function Vector(init_x, init_y, final_x, final_y)
local distance_x = final_x - init_x
local distance_y = final_y - init_y
return {distance_x, distance_y}
end
function GetVectorValue(vector)
return math.sqrt(vector[1] ^ 2 + vector[2] ^ 2)
end
function GetAngleFromVector(x,y)
local reduce = 0
if x < 0 then
reduce = math.rad(180)
end
return math.atan(y/x) - reduce
end