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

4 views (last 30 days)
I have a file (closest_central_points.m) that has a group of 10 closets central points. I have another file (fpep.mat) that has a group of 950+ central points and endpoints triplets. I have third file (closest_central_points_chords.m) that has a line (chord) created from one central point to another. I need an efficient way to find and store the angles between these chords and the lines made between the central points and the endpoints (see attached pic). I have also attached related files. Thanks in advance for your help!

Accepted Answer

Jim Riggs
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
  10 Comments
Steve
Steve on 12 Oct 2019
Thank you for all your help Jim! You really know your stuff.

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!