Question: How to determine an angle in [-Pi,Pi]?

Hello,

After trigonometric manipulations in a mechanical problem, I can obtain the desired angles but defined with modulo 2Pi.

I would like to program or find a function which can do this operation :

While angle doesn't belong to [-Pi, Pi]

do 

  If angle > Pi then do angle = angle - 2Pi

  If angle < - Pi then do angle = angle + 2Pi

end

Is there an existing function which can do this operation ?

Otherwise, may you help me to program it ?

Thanks a lot for your help

Please Wait...