DLiKS
DLiKS

Reputation: 1596

Reflecting Angles in the Y Axis

I'm currently to reflect an angle in the Y axis using 'Pi - angle'. The angle system I'm using is in radians, with 0 being east, -Pi/2 being north, Pi/2 being south and +/- Pi being west and when I try using the above method to reflect an angle, it frequently returns values above Pi, outside the range. How can I prevent this from happening?

Thanks,

DLiKS

Upvotes: 2

Views: 3424

Answers (4)

kellogs
kellogs

Reputation: 2857

By first having your initial angle modulo-divided by Pi. So, in C language:

angle = fmod(angle, 2*Pi);
if (angle < -Pi)
    angle = angle + 2*Pi;

float inverted = Pi - angle;

The thing is to always normalize your input before further processing.

Upvotes: 2

Jason S
Jason S

Reputation: 189626

Reflection about the x-axis: just use -angle.

Reflection about the y-axis: use

   if (angle >= 0)
      return pi - angle
   else
      return -pi - angle

This creates a branch cut at 0: 3° maps to 177°, whereas -3° maps to -177°. 0 maps to pi. (If you require angles in the [-pi,pi) interval that excludes +pi, change the ">=" to ">".

This also assumes that the input angle is within the [-pi,pi] range, as your problem statement suggests. If not, you need to normalize using a symmetric modulo 2*pi (where smod(x,M) = mod(x+M/2,M) - M/2) first.

Upvotes: 5

Robokop
Robokop

Reputation: 926

Why on earth whould you choose north to be -Pi/2. It breaks all default stuf like sin(angle) = y coordinate on the unit circle.

But to answer your question you can add k*2Pi to all your angles (where k is any integer number) and the angle will stay the same.

Upvotes: 0

9000
9000

Reputation: 40884

Since full circle is 2*pi, you ca always subtract 2*pi and have the angle back in range.

Upvotes: 0

Related Questions