Plot a family of circles in 3D

4 ビュー (過去 30 日間)
Snirisa  Gödel
Snirisa Gödel 2013 年 10 月 2 日
コメント済み: Snirisa Gödel 2013 年 10 月 3 日
I have the following code for plotting 100 circles in separate height planes where the radius increases from 1 to 100.
if true
for r=1:1:100
t=linspace(0,2*pi);
x=r*cos(t);
y=r*sin(t);
for h=100:100:10000
z = 100 * r * ones(1, length(t));
plot3(x,y,z);
if r == 1 && h == 100
hold on;
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
end
drawnow;
end
end
Like this:
[1]: http://i.stack.imgur.com/dsPX1.png
*Question*
Now I want to change the code in order for the radius to *decrease* from 100 to 1, i.e turn the cone upside down. So the code should probably read like this but i can't get it to work:
for r=100:-1:1
t=linspace(0,2*pi);
x=r*cos(t);
y=r*sin(t);
for h=100:100:10000
z = 100 * r * ones(1, length(t));
plot3(x,y,z);
if r == 100 && h == 100
hold on;
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
end
drawnow;
end
end

採用された回答

Harsheel
Harsheel 2013 年 10 月 3 日
編集済み: Harsheel 2013 年 10 月 3 日
The height is controlled by 'z' and not 'h'. In the first case, when r=1, z= 100*1*k (where k=ones(1, length(t))). If you want to reverse the cone then, z should be 100*1*k when r=100. Which means:
z = 100 * (101-r) * ones(1, length(t));
  1 件のコメント
Snirisa  Gödel
Snirisa Gödel 2013 年 10 月 3 日
Thank you, I appreciate it.

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

その他の回答 (1 件)

Youssef  Khmou
Youssef Khmou 2013 年 10 月 3 日
Sniriza,
I agree with Harsheel, or you can simply add a minus to z :
z = -(100 * r * ones(1, length(t)));

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by