Draw line between several points 3d

Hi,
I want to draw a line between several points to form a helix. I have matrix multiplication to create several S=[x;y;z] matrices. I managed to plot the points on 3D. But I couldn't connect the points together. So far, I have the following;
D=[-3.1869;5.8209;-0.9806]
theta=0
delta=0
a=0
while a<72
a=a+1
theta=theta+pi/10
delta=delta+1
Hz=[cos(theta),-sin(theta),0;sin(theta),cos(theta),0;0,0,(delta/-0.98058067569092)+1]
S=Hz*D
scatter3(S(1),S(2),S(3))
hold on
end
I tried to write "line(S(1),S(2),S(3))" inside and outside the while loop. But it didn't do. Any help will be appreciated. Thank you.

1 个评论

First, lets format your code as code:
D=[-3.1869;5.8209;-0.9806]
theta=0
delta=0
a=0
while a<72
a=a+1
theta=theta+pi/10
delta=delta+1
Hz=[cos(theta),-sin(theta),0;sin(theta),cos(theta),0;
0,0,(delta/-0.98058067569092)+1]
S=Hz*D
scatter3(S(1),S(2),S(3))
hold on
end

请先登录,再进行评论。

回答(1 个)

Here is code that will draw the helix with markers for each point.
D=[-3.1869;5.8209;-0.9806]
theta=0
delta=0
a=0
lastS = nan(3,1); %Add storage to save the last computed point.
view(3);
while a<72
a=a+1
theta=theta+pi/10
delta=delta+1
Hz=[cos(theta),-sin(theta),0;sin(theta),cos(theta),0;
0,0,(delta/-0.98058067569092)+1]
S=Hz*D
% Use the line command to draw individual line segments.
line( [lastS(1) S(1)], [lastS(2) S(2)], [lastS(3) S(3)], 'Marker', 'o' );
% And store the latest S to use to draw next line.
lastS = S;
end

类别

帮助中心File Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

标签

Community Treasure Hunt

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

Start Hunting!

Translated by