0

I am using atan2() to find the angle between x,y values. I understand atan2 method returns a numeric value between –pi and pi. How do I map that value to [-pi/4, pi/4]. The question is related to this Limiting atan2 to specific angle ranges but I couldn't understand it well.

if (a > pi/4):
  a -= 2 * pi/4
  return a
elif(a <= -pi/4):
  a += 2 * pi/4
return a

1 Answers1

0

If you want to scale the angle down, just divide it:

return a/4

If you want to limit it to a certain range, use min and max

return max(-pi/4, min(pi/4, a))
Barmar
  • 741,623
  • 53
  • 500
  • 612