Here is the code, I am trying to get the angle of rotation. I am rotating an image around a dial. I am getting all the angles right except when it reaches 270 degree it does some funky stuff. The angle changes to negative. It works fine from 0 to 270 but i cant get it to display angle between 270 to 360..Please give me some suggestions
this.rotate = function(x){
this.node.style.MozTransform="rotate("+x+"deg)";
this.node.style.WebkitTransform="rotate("+x+"deg)";
this.node.style.OTransform="rotate("+x+"deg)";
this.node.style.msTransform="rotate("+x+"deg)";
this.node.style.Transform="rotate("+x+"deg)";
myintID = setInterval(function(){
//Math!
angleFromEye = Math.atan2((cursorLocation.y-self.my_y), cursorLocation.x- self.my_x)*(180/Math.PI)+ 90;
//Rotate
self.rotate(angleFromEye);
Actually the angle is negative for the values -90 to 0 also, but you add 90 to the angle, so you don’t see that.
Simply add 360 to the angle when it’s negative: