Rotation based on event coordinates

Hello, I am trying to achive a rotation function that, whenever user clicks to a place on screen, the little circle in the middle of the screen rotates to that direction. What I can not do is, I can not determine the direction of the rotation.
Below is my code. what I want to do is, I want the circle to rotate with the closest path and does not make a full circle to go to a location.

Also another problem I am having is with the rotation values, as far as I know on math, the 90 degrees should point upwards, but when I use player.rotation = 90 it shows the 270* and looks downwards. any ideas.

  
 if (event.phase == "began") then  
 local yPos = player.y - event.y  
 local xPos = player.x - event.x  
 rotationAngle = math.deg((math.atan2(yPos,xPos))) + 180  
 print("Rot Angle ".. rotationAngle .." / Player Rotation ".. player.rotation)  
 --transition.to(player, {time=500, rotation = rotationAngle })  
  
 elseif (event.phase == "ended") then  
 print(math.abs(-rotationAngle - player.rotation))  
 if (math.abs(rotationAngle - player.rotation) \<= 180 ) then  
  
 print("Small")  
 player:rotate(rotationAngle)  
  
 --transition.to(player, {time=500, rotation = rotationAngle })  
  
 elseif(math.abs(rotationAngle - player.rotation) \> 180) then  
 print("big")  
 player:rotate(-rotationAngle)  
  
 --transition.to(player, {time=500, rotation = rotationAngle })  
  
 end  
 --player.rotation = -rotationAngle  
  
 return true  
  
 end  
  

[import]uid: 73033 topic_id: 26205 reply_id: 326205[/import]

The thing I found is when I calculate the angle that the event occured with atan2:

local yPos = player.y - event.y
local xPos = event.x - player.x

print("Event x: “… event.x …” XPos "… xPos … “Event y: “… event.y … " YPos”… yPos …” Degree: "… math.deg(math.atan2(yPos, xPos)) )
–rotationAngle = math.deg((math.atan2(yPos,xPos))) + 180
rotationAngle = (math.atan2(yPos, xPos)) * (180/math.pi)

it returns the correct angle. But when I pass it to rotation or to transition.to it rotates to the opposite direction. If the angle I click is lets say 40* it rotates to 360-40 = 320*

and I dont know why.

[import]uid: 73033 topic_id: 26205 reply_id: 106215[/import]