MATLAB: How can i measure Angle in 3-D

3d

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?

Best Answer

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.