How to create for loop for calculating angle between 3 3D points?
Ältere Kommentare anzeigen
Hi there!
I want to create a for loop that calculates the angle between three 3D points. I have a double called 'data3D' that contains 1 row with several points in 3D space. col 1 = pt1_x, col 2 = pt1_y, col 3 = pt1_z, col 4 = pt2_x ..... For this calculation I only need the xyz coordinates for pt1.
data3D =
-.3 .2 -.3 -.5 .6 -.3
I have a double called 'Coordinates' that contains a varying number of rows, and constant number of columns. col 1 = x, col 2 = y, col 3 = z. The number of rows varies based on how many events occur in a single observation, but columns are consistent throughout.
Coordinates =
-.6 .5 -4.1
-.9 .4 -4.1
-1.1 .2 -4.2
I want my for loop to calculate the angle between my contact point (pt 1, data3D) and each subsequent point in Coordinates. i.e. I want to first calculate the angle between the vector (pt1 -> Coordinates(row1)) and the vector (pt1 -> Coordinates(row2)). The next calcuation should be the angle between vector (pt1 -> Coordinates(row2)) and the vector (pt1 -> Coordinates(row3)) and so forth.
For now, my for loop is structured like this, how would I structure the calculation formula?
nobservations1 = size(Coordinates,1);
icoordinates1 = nobservations1 - 1; %creates a variable that consists of number of observations -1
scanAngles = []; % create empty vector to store angles
for i_coord1 = 1:icoordinates1 %for each observation
curangle =
scanAngles = [scanAngles curangle];
end
Any help with this would be greatly appreciated, I'm a MATLAB novice and would love to learn!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Calendar finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!