[SciPy-User] difference of angles - to be between -180 and + 180

Sebastian Haase seb.haase@gmail....
Wed Nov 18 10:00:19 CST 2009


Hi,

Does anyone have a function that calculates delta-angles taking the
wrap-around at 180 degrees into account ?

I'm thinking of a function like:
>>> diffAngle(190, -10)
160

My current version looks like this:
def diffAngle(a1,a0):
    """
    return a1-a0
    handle wrap-around for -180 and +180
    """
    d = a1-a0
    if d < -180:
        d=360+d
    if d> 180:
        d=360-d
    return d
diffAngle=np.vectorize(diffAngle)


But I'm not sure if this is handling all cases correctly ;-(
Especially I have problems regarding the correct sign - in cases like this:
diffAngle(20, -170) where I was expecting -170 , but I get 170.

Thanks,
Sebastian Haase


More information about the SciPy-User mailing list