Equivalence of directions (a programming question)
Offhand I'd say that you would probably benefit from using polar coordinates instead of cartesian coordinates, but I haven't used polar coordinates with enough regularity to come up with an algorithm off the top of my head.