Fastest way to find the rotation of a vector

Posted by kriss on Stack Overflow See other posts from Stack Overflow or by kriss
Published on 2010-05-28T16:56:24Z Indexed on 2010/05/28 17:12 UTC
Read the original article Hit count: 193

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about python

Related posts about optimization