# sign of the angle between two vectors

This topic is 4764 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am currently using dot product to calculate the angle between two vectors effective from 0..pi but I would like to extend this to account for vector orientation so that my function is effective for full 2pi rotation. Does anyone know how to get the sign of the angle between two 2D vectors?

##### Share on other sites
well i could be wrong but,

i don't think it's possible/makes sense
because the dotproduct gives the 'shortest' angle between 2 vectors,
if you want the angle -> 2pi - angle :)

in my opinion there's no such thing, if maybe you can make yourself clear for what purpose you need it

##### Share on other sites
In 2D, you can measure angles modulo 2π: you can rely on the sign of the determinant (a.x*b.y-a.y*b.x) to get the orientation of the angle (positive → counterclockwise). In 3D, the angle between two vectors is only defined modulo π. You might rely to some extent on the direction of the cross-product vector (which, as you may guess, is an extension of the above-mentioned technique), but that requires you to define an arbitrary reference vector to separate 'positive' from 'negative' (e.g. dot the resulting vector with the z axis: (ab)⋅k, and breaks down when the cross-product vector is in the normal plane to the reference vector.

##### Share on other sites
acos(dot / magnitudes) * Sgn(Vector1.X * Vector2.Y - Vector1.Y * Vector2.X)

did the trick =). I am making a top down level editor for my game because doing it by hand was taking to long, so I wanted a function what would create connected walls; i needed to be able to get the angle between the mouse_vector, and the vector of the currentwall in order to project where the next wall would be placed with respect to the mouse position. the normal acos worked fine but i could only create additional walls what had angles 0<=x<180 =)

##### Share on other sites
you can also get the angle in the range [-Pi, Pi] like so

float dot = v1.x*v2.x + v1.y*v2.y;
float cross = v1.x*v2.y - v1.y*v2.x;
float angle = atan2(cross, dot);