Fastest way to find the rotation of a vector
- by kriss
I have two 2D vectors, say u and v, defined by cartesian coordinates.
Imagine that vectors are needles of a clock. I'm looking for the fastest way to find out, using python, if v is after or before u (or in other words find out in wich half plane is v, regarding to position of u). For the purpose of the problem if vectors are aligned answer should be before.
It seems easy using some trigonometry, but I believe there should be a faster way using coordinates only.
My test case:
def after(u, v):
"""code here"""
after((4,2), (6, 1)) : True
after((4,2), (3, 3)) : False
after((4,2), (2, 1)) : False
after((4,2), (3, -3)) : True
after((4,2), (-2, -5)) : True
after((4,2), (-4, -2)) : False