Angle about...

Started by
7 comments, last by kelaklub 19 years, 7 months ago
Can someone tell me how to compute the angle between two 3D vectors, v1 and v2 where the angle is taken to be counterclockwise about v3 (v3 is assumed to be perpendicular to v1 and v2). Thanks.
Advertisement
Dot product works.

v1•v2 = |v1||v2| cos(angle)

|v| = magnitude
Dot product obviously doesn't work since it is commutative (for vectors with real entries), so clockwise/anticlockwise information is lost.

You need to do a cross product for that,

aXb = |a||b|sin(theta) _n_

where _n_ is the vector perpendicular to a and b (can't remember if its left or right handed though). You should be able to solve the above equation for theta pretty easily.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Thanks, i'll give these a whirl.
I am confused by this formula...

aXb = |a||b|sin(theta) _n_

First, I thought you could not divide a vector by another vector. And if you can, do you divide one vector's x by the other's x, and so on?

Second, if "a cross product b" (aXb) gives you a perpendicular vector and you are dividing by another perpendiculalar vector _n_, won't the formula just be...

sin(theta) = 1 / (|a||b|)

Divide aXb by |a||b|, call this vector r (say).

r = sin(theta) _n_

_n_ is the axis you want to rotate around (normalised) - that's an INPUT to this equation.
Solve for any of the coordinates of the resultant vector to get the answer.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
I am still confused by this...

Solve for any of the coordinates of the resultant vector to get the answer.

How can you do...

sin(theta) = someVector / _n_;
angle between A and B, looking from C:

vec3 cross=CrossProduct(A,B);//cross is perpendicular to A and B
double dot=DotProduct(A,B);
double angle=atan2(length(cross),dot);
if(DotProduct(cross,C)<0) angle=-angle;

note that
1: angle is in radians
2: it may have opposite sign to what you want(depends to hand of system). You may need to change "<" to ">"
That's amazing. It works perfectly. Thank you so much.

This topic is closed to new replies.

Advertisement