Draw line between several points 3d

5 vues (au cours des 30 derniers jours)
Jamie Prince
Jamie Prince le 9 Mar 2016
Commenté : Jamie Prince le 9 Mar 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 commentaire
Daniel Armyr
Daniel Armyr le 9 Mar 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

Connectez-vous pour commenter.

Réponses (1)

Daniel Armyr
Daniel Armyr le 9 Mar 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
  1 commentaire
Jamie Prince
Jamie Prince le 9 Mar 2016
Thank you so much! You are a lifesaver!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by