import math def rotate(v, angle): x, y = v c = math.cos(angle) s = math.sin(angle) return (x * c - y * s, x * s + y * c) def angle_of(v): return math.atan2(v[1], v[0])