matlabvectorgeometrycoordinatescross-product

Cross product of 2d vectors


I have two coordinate vectors:

coor1 = [4 2];
coor2 = [4.3589 1];

and I want to find the angle of the rotation, where mathematically it is given by the equation:

enter image description here

where the numerator is the cross product between the two coordinate pairs and the denominator is the dot product.

The problem is that in MATLAB, a cross product isn't possible with 2-element vectors. Running the following code:

ang = atan2(norm(cross(coor1,coor2)),dot(coor1,coor2));

produces this error:

Error using cross
A and B must be of length 3 in the dimension in which the cross product is taken. 

Is there any way to make cross work? Working this out by hand, the angle of the rotation of both coordinate should be 13.6441.


Solution

  • Why not use the inverse cosine (arccos) instead?

    coor1 = [4 2];
    coor2 = [4.3589 1];
    
    % normalize the vectors:
    d1 = coor1 ./ norm(coor1);
    d2 = coor2 ./ norm(coor2);
    
    ang = acosd(dot(d1,d2));