Discrepancy between dot product and cross product

Discrepancy between dot product and cross product

Post by michalis » Sun, 11 Jan 2004 11:57:25


Hi,

I am trying to find the angle between two vectors. This
is going to be between -pi and pi and positive for counterclockwise
angles.
Using dot product I seem to get the correct results but I can't
interpret
the result for the cross product. Can someone help?
I attach a snippet and some explanation below.
--------------------------------------------------------------------
v1 = [0.0023 -0.0439];
v2 = [1 0];
v1_3D = [v1 0];
v2_3D = [v2 0];

CP = cross(v2_3D, v1_3D); % order matters: rotate v2 to v1

sign = 1;
if CP(3) < 0 % clockwise acute angle
sign = -1;
end

angleDot = sign*acos( dot(v1,v2)/(norm(v1)*norm(v2)) )
angleCross = sign*acos( norm(CP)/(norm(v1_3D)*norm(v2_3D)) )

--------------------------------------------------------------------

Now: acos(dot(v1,v2)/(norm(v1)*norm(v2))) -> 1.5185 which seems to be
the correct angle (without the sign)

However,
acos( norm(CP)/(norm(v1_3D)*norm(v2_3D)) ) -> 0.0523, that appear to
be
pi/2 - 1.5185.

Does anyone know why this happens? I expected them to give the same
result.

thanks
michalis
 
 
 

Discrepancy between dot product and cross product

Post by allno » Sun, 11 Jan 2004 23:46:05


Computing the angle from the dot product goes, according to
my maths book,

cos(angle) = | a dot b | / |a||b|

while computing the angle from the cross product goes, according to
the same maths book, as

sin(angle) = | a cross b | / |a||b|.

HTH.

Rune

 
 
 

Discrepancy between dot product and cross product

Post by michalis » Mon, 12 Jan 2004 05:14:18

> Computing the angle from the dot product goes, according to

Of course you are right!!
That is absolutely my mistake!

Thanks for the help!
michalis