import math


def vToA( x, y, a ):
    """calculate angle from a 2D vector and default value"""
    if y == 0:
        # dangerous special case (avoids div by 0 in dx/dy)
        if x > 0:
            return math.pi * 0.5
        elif x < 0:
            return -math.pi * 0.5
        else:
            # don't change angle... previous is probably best
            return a
    else:
        # safe to use atan technique
        a = math.atan( x / y )
        if y < 0:
            # inverted
            a += math.pi
        return a