# What is the best way to find angles between these two lines?

4 views (last 30 days)

Show older comments

##### 0 Comments

### Accepted Answer

Jim Riggs
on 10 Oct 2019

Edited: Jim Riggs
on 10 Oct 2019

The angle between vectors is determined using the vector dot product.

Calculate the unit vectors and angles as follows:

v1x = cp_x2 - cp_x1; % vector 1 components

v1y = cp_y2 - cp_y1;

d1 = sqrt(v1x^2 + v1y^2); % magnitude of vector 1

u1 = [(v1x/d1, v1y/d1)]; % unit vector 1

v2x = ep_x1 - cp_x1; % vector 2 components

v2y = ep_y1 - cp_y1;

d2 = sqrt(v2x^2 + v2y^2); % magnitude of vector 2

u2 = [v2x/d2, v2y/d2]; % inut vector 2

v3x = cp_x1 - cp_x2; % vector 3 components

v3y = cp_y1 - cp_y2;

d3 = sqrt(v3x^2 + v3y^2); % Vector 3 magnitude

u3 = [v3x/d3, v3y/d3]; % Unit vector 3

v4x = ep_x2 - cp_x2; % vector 4 components

v4y = ep_y2 - cp_y2;

d4 = sqrt(v4x^2 + v4y^2); % vector 4 magnitude

u4 = [v4x/d4, v4y/d4]; % unit vector 4

a1 = acos(dot(u1,u2)); % angle between vector 1 and vector 2

a2 = acos(dot(u3,u4)); % angle between vector 3 and vector 4

### More Answers (0)

### See Also

### Categories

### Products

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!