I am trying to plot multiple helices in one plot but for some reason I am only getting one helix with my code below...
clc;
close all;
n = input('number of turns ');
r = input('radius ');
h = input('length ');
w = input ('number of wires ');
e = (2*pi)/(w/2); %theta (where the wire is starting)
for i=1:1:w/2
t = (i-1)*e:pi/100:(n*2*pi)+(e*(i-1)); %t value for CCW helices
x = r*sin(t);
y = r*cos(t);
z = (h/(n*2*pi))*t;
end
plot3(x,y,z, 'blue') %plot CCW helices

2 件のコメント

Jan
Jan 2018 年 6 月 13 日
The problem is, that you overwrite the values of t,x,y,z in each iteration instead of accumulating them.
Guillaume
Guillaume 2018 年 6 月 18 日
@Julia, please do not close the question. It's disrepectful of the people who took time to answer your question.

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

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 6 月 13 日
編集済み: KALYAN ACHARJYA 2018 年 6 月 13 日

0 投票

clc; close all;
n=input('number of turns ');
r=input('radius ');
h=input('length ');
w=input('number of wires ');
e=(2*pi)/(w/2); %theta (where the wire is starting)
for i=1:1:w/2
t =(i-1)*e:pi/100:(n*2*pi)+(e*(i-1)); %t value for CCW helices
x=r*sin(t);
y=r*cos(t);
z=(h/(n*2*pi))*t;
plot3(x,y,z) %plot CCW helices
hold on;
end
hold off;

8 件のコメント

Julia Morandi
Julia Morandi 2018 年 6 月 13 日
That is still only giving one helix, I am trying to plot multiple helices (number of helices should be half the number of wires).
Guillaume
Guillaume 2018 年 6 月 13 日
Kalyan code is actually plotting floor(w/2) helices and is correct according to your equations.
However, since they have all the same radius and phase and the only thing that change per helix in your original equation is the start and end point of t, they all overlap. If you remove the 'blue' argument to plot3 and let matlab automatically assign different colours to the helices, you'll see how they overlap.
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 6 月 13 日
Thanks Guilaume
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 6 月 13 日
number of turns 20
radius 6
length 10
number of wires 10
>>
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 6 月 13 日
Change for loop length, it will more visible
for i=1:1:w
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 6 月 13 日
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 6 月 13 日
e=40;
plot3(x,y,z,'linewidth',2) %plot CCW helices
hold on
Enter
number of turns 3
radius 4
length 20
number of wires 10
Result
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 6 月 13 日

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

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

質問済み:

2018 年 6 月 13 日

コメント済み:

2018 年 6 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by