|
-- 返回弧度表示的y/x的反正切
function Util:atan2(y, x)
if x > 0 then return math.atan(y / x) end
if y >= 0 and x < 0 then return math.atan(y / x) + math.pi end
if y < 0 and x < 0 then return math.atan(y / x) - math.pi end
if y > 0 and x == 0 then return math.pi / 2 end
if y < 0 and x == 0 then return -math.pi / 2 end
if y == 0 and x == 0 then error("y and x is zero!") end
end |
|