# How can i measure Angle in 3-D?

4 visualizzazioni (ultimi 30 giorni)
Mahmoud Sami il 8 Set 2018
Commentato: Mahmoud Sami il 22 Set 2018
I have points
S =[0.5360 0.8850 2.3962;
0.5360 0.8850 2.4291;
0.5436 0.1708 1.8550;
0.7532 0.8089 0.9649;
0.9630 0.4010 1.1216]
plot3(S(:, 1), S(:, 2), S(:, 3), 'b.', 'MarkerSize', 30, 'LineWidth', 2);
grid on;
These points are connected to make connected lines. How can I measure the angle between the lines?
##### 2 CommentiMostra NessunoNascondi Nessuno
KALYAN ACHARJYA il 8 Set 2018
Angle between?
Mahmoud Sami il 8 Set 2018
Modificato: Mahmoud Sami il 8 Set 2018
The 1st line connected between the first point and the second one, the second line connected between the second point and the third one, to the end of S. The angle the 1st line and 2nd line. Then 2nd line and 3 rd line.

Accedi per commentare.

### Risposta accettata

Jim Riggs il 9 Set 2018
Modificato: Jim Riggs il 9 Set 2018
The link in the answer by Aquatris is not working for me.
The angle between any two lines is given by the dot product.
Define each line segment as a vector from one point to the next in the point sequence, i.e. segment D1 = P2 - P1 = {P2x-P1x, P2y-P1y, P2z-P1z}. Likewise, define segment D2 as P3 - P2 = {P3x-P2x, P3y-P2y, P3z-P2z}. Now normalize these two vectors to make then unit vectors U1 = D1/|D1| and U2 = D2/|D2|.
Take the dot product of U1 and U2; this is the cosine of the angle between line segment 1 and 2.
##### 4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Jim Riggs il 11 Set 2018
Modificato: Jim Riggs il 11 Set 2018
If you want some help visualizing the angles in the 3D plot, add the rotation axis to the plot as follows;
Add the calculation of the normal vector for each angle vertex right after the angle calculation inside the for loop:
ang(j) = acosd(dot(U1,U2));
norm(j) = 0.1*cross(U1,U2);
I use a 0.1 scale factor so that this line is not too long in the plot. Now make the 3D plot, and add the normal vectors to the plot as follows:
% The first part is the same as your plot, except I have drawn the lines connecting the points
figure();
plot3(S(:,1), S(:,2),S(:,3),'-ob','MarkerSize',6,'LineWidth',2);
grid on;
axis equal;
% now add the normal vectors
hold on;
for j=1:n-2
Vt = norm(j,:) + S(j+1,:)
plot3([S(j+1,1) Vt(1)], [S(j+1,2) Vt(2)], [S(j+1,3) Vt(3)] 'r','LineWidth',3)
end
These red lines are the rotation axes for each angle. Note that using "axis equal" makes all three axes of equal scale so that line lengths are drawn proportionally, and this makes the angles look right.
Now you can rotate the 3D plot and the red lines will help you line up the view to visualize the angles.
The five points in your S matrix define 4 line segments and 3 angles. I calculate the three angles to be 51.2, 93.2, and 48.8 degrees.
Mahmoud Sami il 22 Set 2018

Accedi per commentare.

### Più risposte (1)

Aquatris il 9 Set 2018
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Mahmoud Sami il 11 Set 2018

Accedi per commentare.

### Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by