Flip an angle using radians

Hello everyone that you have math, wakes up there!

I am struggling with a math problem. I hope you can help me. I calculated the angle of direction using radians. In OpenGL ES, I move my boyfriend by changing my meaning 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 right direction. However, I decided to leave my sprite “locked” in the middle of the screen and instead move the background. This requires me to reverse the calculated angle. If my sprite direction in radians is equivalent to 90 degrees, I want to convert it to 270 degrees. Again, keeping everything in radians.

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

Thanks in advance....

-Scott

+3
source share
3 answers

Add / Subtract pi.

+14
source

object_sprite.rotation = warp_direction - 3.14;

0
source

Pi, 2 Pi ( [0; 2 Pi]).

JavaScript:

function invertAngle(angle) {
  return (angle + Math.PI) % (2 * Math.PI);
}
0

Source: https://habr.com/ru/post/1732797/


All Articles