Determine position of angle relative to another

2012-08-23

Searching for this problem is not easy. Even though the solution is very, very short. I wouldn't say simple, but I'm fine with that.

So this problem is about having two angles (vectors) with the same origin. I needed to know whether one angle was left of right from the other, when looking at the acute angle (the shortest angle) between the two. The solution, brought on by @aadsm, is to get the cosine of them.

Code:
Math.cos((alpha-beta)+(Math.PI/2))

The result is either positive or negative, which indicates perfectly how the angles are positioned relative to each other. That's great! Because the best solution had come up with so far was about eight or ten different conditions for alpha and beta :p And still didn't work perfectly.

One of these days I'm gonna have to spend some more time figuring out how to get an intuitive feeling of what sin/cos/tan are/do and when to apply them. Ohwell.

Hope it helps you :)