I am making a tank game, using the following to determine the angle from the tank to the cursor
rotate(atan(((mouseY-height/2)*scalar)/((mouseX-width/2)*scalar)));
then drawing my cannon within it (for shortening purpouses its just a rect)
rect(0,-5,30,10);
Then undoing the rotation with the negative of the previously mentioned rotate
Problem is, whenever the angle is from pi/2 to 3pi/2 (quadrants 2 and 3), it gives me the inverse.
To better show this I have made a pointer from where the tank is, to where the cursor is with a line:
ellipse((mouseX-width/2)*(scalar),(mouseY-height/2)*(scalar), 5,5);
line(0,0,(mouseX-width/2)*(scalar),(mouseY-height/2)*(scalar));
When the line is intersecting the rect, it is working correctly
here is a working copypasta that shows my problem
void setup(){
fullScreen();
}
void draw(){
background(255);
translate(width/2, height/2);
scale(height/540.0);
ellipse(0,0,20,20);
rotate(atan(((mouseY-height/2)*(540.0/height))/((mouseX-width/2)*(540.0/height))));
rect(0,-5,30,10);
rotate(-atan(((mouseY-height/2)*(540.0/height))/((mouseX-width/2)*(540.0/height))));
ellipse((mouseX-width/2)*(540.0/height),(mouseY-height/2)*(540.0/height), 5,5);
line(0,0,(mouseX-width/2)*(540.0/height),(mouseY-height/2)*(540.0/height));
}