Discrepancy between dot product and cross product

Discussion in 'MATLAB' started by Michalis, Jan 10, 2004.

  1. Michalis

    Michalis Guest

    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
     
    Michalis, Jan 10, 2004
    #1
    1. Advertisements

  2. Michalis

    Rune Allnor Guest

    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
     
    Rune Allnor, Jan 10, 2004
    #2
    1. Advertisements

  3. Michalis

    Michalis Guest

    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
     
    Michalis, Jan 10, 2004
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.