Reputation: 338
How to calculate obtuse angle between two vectors if both vectors and x axis is given. First vector can be taken as x axis. we can get acute by dot product and acos.
Upvotes: 4
Views: 15253
Reputation: 1
It is necessary to use both dot and cross products to correctly resolve the angle. Angle between vectors u and v is
||atan2(s,c)||
where `s = ||u X v||` (magnitude of the cross product)
and `c = u.v` (dot product)
and atan2
is the 4-quadrant inverse tan function
and ||*||
denotes magnitude (norm).
This will always return an angle between 0 and 180 degrees.
Upvotes: 0
Reputation: 21848
Before applying acos, check if the dot product is negative. If negative, the angle is obtuse :)
Further, as acos has a range of 0 to pi, you will do fine as long as you do not want reflex angles (>pi)
Upvotes: 5