- Remove the "hold on" command from line 5.
- Place the "grid on" command after plotting the first point using "plot3". The updated code snippet would look as follows.
I want to draw a graph in 3D, but the z value is output as 0, so it comes out in 2D. In conclusion, I want to paint in three dimensions. How can I print it in 3D?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
th1 = 0; th2 = 0; th3 =0; th4 =0; th5 = 0; th6 = 0;
ox=0;oy=0;oz=0;
c1 = cos(th1); c2 = cos(th2); c3 = cos(th3); c4 = cos(th4); c5 = cos(th5); c6 = cos(th6);
s1 = sin(th1); s2 = sin(th2); s3 = sin(th3); s4 = sin(th4); s5 = sin(th5); s6 = sin(th6);
hold on
T1 = [c1 -s1 0 0; s1 c1 0 0; 0 0 1 0; 0 0 0 1]; % Determinant for forward kinematics
T2 = [1 0 0 0; 0 0 1 0; 0 -1 0 0; 0 0 0 1];
T3 = [c2 -s2 0 0; s2 c2 0 0; 0 0 1 0; 0 0 0 1];
T4 = [1 0 0 0; 0 1 0 0; 0 0 1 0.6; 0 0 0 1];
T5 = [1 0 0 2; 0 1 0 0; 0 0 1 0; 0 0 0 1];
T6 = [c3 -s3 0 0; s3 c3 0 0; 0 0 1 0; 0 0 0 1];
T7 = [1 0 0 0; 0 1 0 0; 0 0 1 -0.3; 0 0 0 1];
T8 = [1 0 0 0; 0 0 1 0; 0 -1 0 0; 0 0 0 1];
T9 = [c4 -s4 0 0; s4 c4 0 0; 0 0 1 0; 0 0 0 1];
T10 = [1 0 0 0; 0 1 0 0; 0 0 1 0.7; 0 0 0 1];
T11 = [1 0 0 0; 0 0 -1 0; 0 1 0 0; 0 0 0 1];
T12 = [c5 -s5 0 0; s5 c5 0 0; 0 0 1 0; 0 0 0 1];
T13 = [1 0 0 0; 0 0 1 0; 0 -1 0 0; 0 0 0 1];
T14 = [c6 -s6 0 0; s6 c6 0 0; 0 0 1 0; 0 0 0 1];
end1 = T1*[0;0;0;1];
x1 = end1(1); y1 = end1(2); z1 = end1(3); %Calculation to find coordinate values
end2 = T1*T2*[0;0;0;1];
x2 = end2(1); y2 = end2(2); z2 = end2(3);
end3 = T1*T2*T3*T4*T5*[0;0;0;1];
x3 = end3(1); y3 = end3(2); z3 = end3(3);
end4 = T1*T2*T3*T4*T5*T6*T7*T8*[0;0;0;1];
x4 = end4(1); y4 = end4(2); z4 = end4(3);
end5 = T1*T2*T3*T4*T5*T6*T7*T8*T9*T10*T11*[0;0;0;1];
x5 = end5(1); y5 = end5(2); z5 = end5(3);
end6 = T1*T2*T3*T4*T5*T6*T7*T8*T9*T10*T11*T12*T13*T14*[0;0;0;1];
x6 = end6(1); y6 = end6(2); z6 = end6(3);
grid on
plot3(ox, oy, oz, 'ok'), hold on %I want to draw a graph in 3D, but it comes out in 2D.
plot3(x1, y1, z1, 'ok')
plot3(x2, y2, z2, 'ok')
plot3(x3, y3, z3, 'ok')
plot3(x4, y4, z4, 'ok')
plot3(x5, y5, z5, 'ok')
plot3(x6, y6, z6, 'ok')
plot3([ox, x1],[oy, y1],[oz, z1], 'r')
plot3([x1, x2],[y1, y2],[z1, z2], 'g')
plot3([x2, x3],[y2, y3],[z2, z3], 'b')
plot3([x3, x4],[y3, y4],[z3, z4], 'c')
plot3([x4, x5],[y4, y5],[z4, z5], 'm')
plot3([x5, x6],[y5, y6],[z5, z6], 'y')
max_L = 0.6 + 2 + 0.3 + 0.7 + 1;
axis([-max_L max_L -max_L max_L -max_L max_L])
0 comentarios
Respuestas (1)
Shivam
el 4 de Oct. de 2023
From the information you have provided, I understand that you are trying to plot the points in a 3-D graph. Currently, the points are being plotted on a 2-D plane.
You can make the below changes in your code to draw the graph in 3-D.
plot3(ox, oy, oz, 'ok');
hold on;
grid on;
To ensure that the default axes initialization is avoided when using the "hold on" function, placing the "hold on" command after the "plot3" statement is recommended.
I hope it helps.
0 comentarios
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!