MATLAB Answers


Calculate the angle between multiple points

Asked by Laura
on 13 Jun 2013
Latest activity Answered by michael scheinfeild on 9 Jul 2014

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.

  1 Comment

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

Log in to comment.


2 Answers

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));


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.


@Roger: Thanks! I forgot the limitations of cross.

Log in to comment.

Answer by michael scheinfeild on 9 Jul 2014

what is v1 v2 can yo give example


Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today