How can i measure Angle in 3-D?

2 次查看(过去 30 天)
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 个评论
Mahmoud Sami
Mahmoud Sami 2018-9-8
编辑:Mahmoud Sami 2018-9-8
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.

请先登录,再进行评论。

采纳的回答

Jim Riggs
Jim Riggs 2018-9-9
编辑:Jim Riggs 2018-9-9
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 个评论
Jim Riggs
Jim Riggs 2018-9-11
编辑:Jim Riggs 2018-9-11
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
Mahmoud Sami 2018-9-22
Thanks for your answer. Sorry for late feedback.

请先登录,再进行评论。

更多回答(1 个)

Aquatris
Aquatris 2018-9-9
Check out this link which has the answer.

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by