Archived

This topic is now archived and is closed to further replies.

Angle between Vectors

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

Recommended Posts

I have a function to calculate the geometrical angle between two vectors : double AngleBetweenVectors(CVector3 Vector1, CVector3 Vector2) { // Get the dot product of the vectors float dotProduct = Dot(Vector1, Vector2); // Get the product of both of the vectors magnitudes float vectorsMagnitude = Magnitude(Vector1) * Magnitude(Vector2) ; // Get the angle in radians between the 2 vectors double angle = acos( dotProduct / vectorsMagnitude ); // Return the angle in radians return( angle ); } but I want to calculate the angle *directed*, I don''t know if it''s the good word in English ( "angle orienté" en Français =) but I want to have an angle according to the direction of the vectors therefore to have negative angles. How can I do that ?? Thanks.

Share on other sites
In 3-space there is no way to specify such a direction only given two vectors. You need a third "reference" vector with wich to compute the directions against. It works like this, consider being at the reference vector and looking at the two vectors in question. If the rotation is a couter-clockwise one from v1 to v2, then the angle is positive. If it is clockwise from v1 to v2, then the angle is negative.

This can be computed like so, (assuming that ref is not in the plane of v1, v2)

dot = (v1 x v2) dotP ref
if (dot < 0)
clockwise
if (dot > 0)
counter clockwise
if (dot == 0)
ref in plane of v1 v2, no singed angle exists

(NOTE: I haven''t doublechecked those signs, they may be reversed. Note also that they will be reversed between RH and LH coordinate systems.)

How does this work? We are looking at the normal created by the cross product of the two vectors, and seeing if it is pointing toward or away from the reference. Since (v1 x v2) = -(v2 x v1), a rotation in the oppisite direction from a given rotation will always give a different sign for the dot product with ref.

Josh

Share on other sites
I have a question for a similar topic:

Can I do the same to get the angle between 2 vectors on a plane? I need the yaw and pitch between 2 vectors.

Share on other sites
Thanks for ur help MisterAnderson !!

Share on other sites
quote:
Original post by Cybertron
I have a question for a similar topic:

Can I do the same to get the angle between 2 vectors on a plane? I need the yaw and pitch between 2 vectors.

Cybertron,

Please post a separate thread. I see your question leading to a series of posts. Its quite confusing to start a new thread in the middle of an existing one.

You''ll want to ask for clarification on what yaw and pitch actually are, for example. (Hint, you can''t get both a yaw and pitch given only two vectors. Plus, what you can get depends on how you choose to define yaw and pitch.)

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• Forum Statistics

• Total Topics
631710
• Total Posts
3001846
×