Creating an ellipse plot with a for loop
11 ビュー (過去 30 日間)
古いコメントを表示
For some reason my superellipse isn't shown in the figure when I run my code below in MatLab. I don't know where I went wrong, do I need to store the values in some way and then plot these values in the figure? Hope someone can help me out, thanks.
-Somehow the code underneath isn't shown correctly in the square on this website, sorry -
n=2;
a=1;
b=1;
x0=0; % x0,y0 ellipse centre coordinates
y0=0;
for t=0:0.01:2*pi;
if t < 0
x=x0+(abs(cos(t)).^(2/a)) * a*-1*(abs(cos(t)));
y=y0+(abs(sin(t)).^(2/b)) * b*-1*(abs(sin(t)));
end
if t == 0
x=x0+(abs(cos(t)).^(2/a)) * a*0*(abs(cos(t)));
y=y0+(abs(sin(t)).^(2/b)) * b*0*(abs(sin(t)));
end
if t > 0
x=x0+(abs(cos(t)).^(2/a)) * a*1*(abs(cos(t)));
y=y0+(abs(sin(t)).^(2/b)) * b*1*(abs(sin(t)));
end
figure(1)
plot(x,y)
grid on;
grid minor;
end
0 件のコメント
回答 (1 件)
KSSV
2017 年 5 月 22 日
clc ; clear all ;
n=2;
a=1;
b=1;
x0=0; % x0,y0 ellipse centre coordinates
y0=0;
figure(1)
hold on
for t=0:0.01:2*pi;
if t < 0
x=x0+(abs(cos(t)).^(2/a)) * a*-1*(abs(cos(t)));
y=y0+(abs(sin(t)).^(2/b)) * b*-1*(abs(sin(t)));
end
if t == 0
x=x0+(abs(cos(t)).^(2/a)) * a*0*(abs(cos(t)));
y=y0+(abs(sin(t)).^(2/b)) * b*0*(abs(sin(t)));
end
if t > 0
x=x0+(abs(cos(t)).^(2/a)) * a*1*(abs(cos(t)));
y=y0+(abs(sin(t)).^(2/b)) * b*1*(abs(sin(t)));
end
plot(x,y,'.r')
grid on;
grid minor;
end
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!