## How to find angle between two lines?

### Beulah A (view profile)

on 21 Oct 2019 at 8:47
Latest activity Commented on by Beulah A

### Beulah A (view profile)

on 6 Nov 2019 at 9:21

### Bjorn Gustavsson (view profile)

For example, there is line L1 between two points (x1,y1) and (x2,y2). Another line L2 between points (x1,y1) and (x3,y3). I want to find the angle between the lines L1, L2. How to find in MATLAB? I think in matlab there is no predefined function which performs the same.

James Tursa

### James Tursa (view profile)

on 21 Oct 2019 at 16:50

### Bjorn Gustavsson (view profile)

on 21 Oct 2019 at 11:13

A more stable method that what Jos suggested is
v_1 = [x2,y2,0] - [x1,y1,0];
v_2 = [x3,y3,0] - [x1,y1,0];
Theta = atan2(norm(cross(v_1, v_2)), dot(v_1, v_2));
HTH

Beulah A

### Beulah A (view profile)

on 6 Nov 2019 at 9:21
Thanks, This solves my problem.

### Jos (10584) (view profile)

on 21 Oct 2019 at 9:18

Use the dot product between the two vectors (v1 and v2) given by the four x,y pairs points.
Given the formula: dot(v1,v2) = | v1 | x | v2 | x cos(A)
I leave it to you to find the angle A using the matlab functions norm, dot and acos.