## Calculate the angle between multiple points

### Laura (view profile)

on 13 Jun 2013
Latest activity Answered by michael scheinfeild

on 9 Jul 2014

### Jan Simon (view profile)

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.

Jan Simon

### Jan Simon (view profile)

on 13 Jun 2013

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

## Products

No products are associated with this question.

### Jan Simon (view profile)

on 13 Jun 2013

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

### Roger Stafford (view profile)

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

### Jan Simon (view profile)

on 18 Jun 2013

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

### michael scheinfeild (view profile)

on 9 Jul 2014

what is v1 v2 can yo give example

#### Join the 15-year community celebration.

Play games and win prizes!

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