Please correct my joystick trigonometry

Using the touch event’s coordinates, I am trying to calculate the angle in which the joystick is moved towards.

My code below is producing the wrong results:

local adj = event.x - event.xStart;  
local opp = event.y - event.yStart;  
local angle = math.deg( math.atan(opp/adj) );  

Intended output:

 360
 |
 |
 |
180-------------0
 |
 |
 |
 90

[import]uid: 75783 topic_id: 13023 reply_id: 313023[/import]

Try using math.atan2(opp, adj) instead because you need the signs for the opp and adj for the angle to be calculated properly.

More info here:

http://lua-users.org/wiki/MathLibraryTutorial
[import]uid: 27183 topic_id: 13023 reply_id: 47826[/import]