Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flipping an angle using radians

Hello all you math whizzes out there!

I am struggling with a math problem I am hoping you can help me with. I have calculated an angle of direction using radians. Within OpenGL ES I move my guy by changing my point value as such:



spriteLocation.x -= playerSpeed * cosf(playerRadAngle);
spriteLocation.y -= playerSpeed * sinf(playerRadAngle);

// playerRadAgnle is my angle of direction using radians

This works very well to move my sprite in the correct direction. However, I have decided to keep my sprite "locked" in the middle of the screen and move the background instead. This requires me to Reverse my calculated angle. If my sprite's direction in radians is equivalent to 90 degrees, I want to convert it to 270 degrees. Again, keeping everything in radians.

I will admit that my knowledge of Trig is poor at best. Is there a way to figure out the opposite angle using radians? I know I could convert my radians into degrees, then add/subtract 180 degrees, then convert back to radians, but I'm looking for something more efficient.

Thanks in advance....

-Scott

like image 884
Scott Avatar asked Feb 15 '10 02:02

Scott


1 Answers

Add/subtract pi instead.

like image 167
Ignacio Vazquez-Abrams Avatar answered Sep 16 '22 18:09

Ignacio Vazquez-Abrams