How to get the order of two vectors based on their relative angle without computing the angle?

46 Views Asked by At

I've illustrated what I'm looking for here.

In case it is not clear from the image, here is what my problem is:

I have two vectors with the same origin. I want to be able to check if v1 is to the left of v2. It's as if v1 was an axis and i wanted v2 to have a positive angle to it if that makes sense.

I've already tried using atan2(x, y) but I don't know how to make the value consistent when one vector is < 0 and the other is > 0 (when both vectors are facing down)

I've read about possibly doing a 2d cross product (which isn't technically a thing but its done by projecting the two vectors onto an axis) but I'm not sure how to implement it and I don't know if it's a working solution.

I am using Javascript for an html canvas game engine but that is unrelated to the question because I just need to know how to do the math in this case.


I hope that I am clear in what my problem is.

Thanks!

1

There are 1 best solutions below

1
Holmz On

Have you tried atan2(y,x) rather than atan2(x,y)?

One probably also would want to address angles being a bit < Pi and > Pi with some logic. As in the question, "Is 359 degress > 0 or is it anti clockwise?