def wrap_degrees(a, da):
    """ add da to a, but make sure that the resulting angle stays within the -180 to 180 range """
    a2 = a + da
    while a2 > 180:
        a2 -= 360
    while a2 < -180:
        a2 += 360
    return a2