MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Laura
on 13 Jun 2013

I have a matrix A contain x values in the first column and y values in the second column. I want to calculate the angle between vectors.

*No products are associated with this question.*

Answer by Jan Simon
on 13 Jun 2013

Accepted answer

The ACOS and the corresponding ASIN approchs are numerically instable near to multiples of pi (half). Better use the more accurate ATAN2 method:

angle = atan2(norm(cross(v1,v2)), dot(v1,v2));

Roger Stafford
on 17 Jun 2013

In the two-dimensional x-y plane Mathworks' 'cross' function doesn't work. It requires three-element vectors. The two-dimensional expression should be:

angle = atan2(abs(det([v1;v2])),dot(v1,v2));

where v1 and v2 are assumed to be two-element row vectors.

(Corrected)

## 1 Comment

## Jan Simon

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/78931#comment_154774

There is no "angle between points". Do you mean the angle between two vectors?