4 views (last 30 days)

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

Jim Riggs
on 10 Oct 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.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.