I have a sprite that goes around a circle which is transformed on the Y axis by 30%.
The problem i have then is trying to work out the angle from a point from the center of the circle. For some reason, it always gives me a negative value between -73 and -116 degrees.. I can't work out why this is, whether its a maths error or infact as it is meant to be due to the way the circle is shaped.
This is my function which calculates the angle:
for (var i = 0; i < obj.length; i++) {
var delta = Date.now() - obj[i].start;
var angle = obj[i].rotSpeed * delta;
obj[i].x = obj[i].radius * Math.cos(angle);
obj[i].y = obj[i].radius * scaleFactor * Math.sin(angle);
// get the angle from center in degrees
var vectorX = obj[i].x - obj[i].originX;
var vectorY = obj[i].y - obj[i].originY;
var angle = Math.atan2(vectorY, vectorX) * 180 / Math.PI;
}
I have also got the animation running here where it will display the degrees during it's rotation: http://jsfiddle.net/odx7rtou/
I am wondering if some one can explain why the degrees do not return in a full 360 amount such as from -180 to +180. And how can i correct for this?
My main goal here is to get which of the four quadrants of the circle the object is currently in as this will effect the order in which I draw things for when I want it go behind or in front of other objects.
Hope you can help.