MATLAB Answers

Laura
0

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?

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

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)

@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


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!