MATLAB Answers

Laura

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

Jan Simon
on 13 Jun 2013

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

Tags

Products

No products are associated with this question.

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

  2 Comments

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)

Jan Simon
on 18 Jun 2013

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


Answer by michael scheinfeild on 9 Jul 2014

what is v1 v2 can yo give example

  0 Comments


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today