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

12 visualizaciones (últimos 30 días)
Steve
Steve el 10 de Oct. de 2019
Comentada: Steve el 12 de Oct. de 2019
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!

Respuesta aceptada

Jim Riggs
Jim Riggs el 10 de Oct. de 2019
Editada: Jim Riggs el 10 de Oct. de 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 comentarios
Jim Riggs
Jim Riggs el 10 de Oct. de 2019
One way to do this is to define a structure that contains all of the information that you want, and as the values are calculated you put them into the structure. When you are done, wou have all of the information in one place and organized as you like. I like this method because it allows you to package a lot of parameters together in one place.
For example, you might start with defining the structure and placing your data in the structure;
load('Triplets.mat');
struct.Triplets = Triplets; % creates a structure named "struct" and
% places the Triplets array in the structure.
Run your script to calculate fpep from Triplets, and add it to the structure;
struct.fpep = fpep;
At this point, the structure contains two sets of data;
struct.Triplets
struct.fpep
Add your user-specified parameters that will be used to perform calculations on the data:,
struct.refpt = 290; % reference point to start from
struct.n = 10; % number of nearest points
As you perform calculations, keep adding variables to the structure as they are computed; anything that you want to keep.
struct.xyNearest = xyNearest;
struct.IZ = IZ;
struct.chord = chord;
... etc.
When you are done, you have a single structure that contains everything that you want, including the original data. You can pass this structure around in your code as an argument to a function. This is a very handy technique to maniupulate a lot of data and variables in one package.
Steve
Steve el 12 de Oct. de 2019
Thank you for all your help Jim! You really know your stuff.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by