Draw line between several points 3d

12 Ansichten (letzte 30 Tage)
Jamie Prince
Jamie Prince am 9 Mär. 2016
Kommentiert: Jamie Prince am 9 Mär. 2016
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 Kommentar
Daniel Armyr
Daniel Armyr am 9 Mär. 2016
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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Daniel Armyr
Daniel Armyr am 9 Mär. 2016
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

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by