Understanding math used to determine if vector is clockwise / counterclockwise from your vector
- by MTLPhil
I'm reading Programming Game AI by Example by Mat Buckland. In the Math & Physics primer chapter there's a listing of the declaration of a class used to represent 2D vectors.
This class contains a method called Sign. It's implementation is as follows
//------------------------ Sign ------------------------------------------
//
// returns positive if v2 is clockwise of this vector,
// minus if anticlockwise (Y axis pointing down, X axis to right)
//------------------------------------------------------------------------
enum {clockwise = 1, anticlockwise = -1};
inline int Vector2D::Sign(const Vector2D& v2)const
{
if (y*v2.x > x*v2.y)
{
return anticlockwise;
}
else
{
return clockwise;
}
}
Can someone explain the vector rules that make this hold true?
What do the values of y*v2.x and x*v2.y that are being compared actually represent?
I'd like to have a solid understanding of why this works rather than just accepting that it does without figuring it out. I feel like it's something really obvious that I'm just not catching on to.
Thanks for your help.