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:
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
.
rad2deg(atan2(coor2(2)*coor1(1)-coor2(1)*coor1(2), dot(coor1,coor2)))
? – avermaetrad2deg(atan2(...))
is unnecessary, one can simply useatan2d
instead. – Dev-iL