Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function math.atan2(y, x)
- if x > 0 then -- regular case (first or fourth quadrants, the range of atan)
- return math.atan(y/x)
- elseif y >= 0 and x < 0 then -- second quadrant case
- return math.atan(y/x + math.pi)
- elseif y < 0 and x < 0 then -- third quadrant case
- return math.atan(y/x - math.pi)
- elseif y > 0 and x == 0 then -- pointing up
- return math.pi/2
- elseif y < 0 and x = 0 then -- pointing down
- return -math.pi/2
- else -- special quirk if y = 0 and x = 0
- return 0
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement