Draw line between several points 3d

8 ビュー (過去 30 日間)
Jamie Prince
Jamie Prince 2016 年 3 月 9 日
コメント済み: Jamie Prince 2016 年 3 月 9 日
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 件のコメント
Daniel Armyr
Daniel Armyr 2016 年 3 月 9 日
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 件)

Daniel Armyr
Daniel Armyr 2016 年 3 月 9 日
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
  1 件のコメント
Jamie Prince
Jamie Prince 2016 年 3 月 9 日
Thank you so much! You are a lifesaver!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by