Mothback/code/math.lua

28 lines
482 B
Lua
Raw Normal View History

2021-10-16 23:06:11 +00:00
function math.sign(x)
2022-02-26 02:56:53 +00:00
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)
2022-02-26 02:56:53 +00:00
local distance_x = final_x - init_x
local distance_y = final_y - init_y
return {distance_x, distance_y}
end
function GetVectorValue(vector)
2022-02-26 02:56:53 +00:00
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