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 CenterFile 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