在追踪曲线时填充极花图

发布于 2025-01-23 09:49:51 字数 762 浏览 4 评论 0原文

我想为绘制一个极地花情节动画。我希望结果看起来像这个情节:

但是当前的结果看起来像:

我一直在将坐标重新排列到多维结构x1y1中,因此它不仅仅是填充作为普通的余弦波。帮助您非常感谢。

clear;close all;
x = 0:0.01:pi*2;
r = cos(2*x).*sin(2*x);
figure
polar(x,r);
input('Press ENTER to start.');
hold on;
for x0 = x
  r0 = cos(2*x0).*sin(2*x0);
  polar(x0,r0,'o');
  x1 = [x0 2*pi 0];
  r1 = [r0 0 0];
  fill(x1,r1,'b');
  pause(0.033);
end
hold off;

I'd like to animate a polar flower plot being drawn. I would hope for the result to look like this plot:
enter image description here

However the current result looks like this:
enter image description here

I've been rearranging the coordinates into multidimensional structs x1 and y1, so it isn't just filling in as a plain cosine wave. Help is much appreciated.

clear;close all;
x = 0:0.01:pi*2;
r = cos(2*x).*sin(2*x);
figure
polar(x,r);
input('Press ENTER to start.');
hold on;
for x0 = x
  r0 = cos(2*x0).*sin(2*x0);
  polar(x0,r0,'o');
  x1 = [x0 2*pi 0];
  r1 = [r0 0 0];
  fill(x1,r1,'b');
  pause(0.033);
end
hold off;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声无音无过去 2025-01-30 09:49:51

填充(..)采用笛卡尔坐标,而不是极性坐标。
因此,您必须在调用填充()之前将极性参数转换为笛卡尔坐标。然后,除非需要极性框架,否则不需要调用极地(..)。

th = 0:0.01:pi*2;
r = cos(2*th) .* sin(2*th);
clf
x = r .* cos(th);
y = r .* sin(th);
c = fill(x,y,'b');
axis square tight

fill(..) takes cartesian coordinates, not polar ones.
So you must convert polar parameters into cartesian coordinates before calling fill(). Then, unless you need the polar frame, calling polar(..) is not required.

th = 0:0.01:pi*2;
r = cos(2*th) .* sin(2*th);
clf
x = r .* cos(th);
y = r .* sin(th);
c = fill(x,y,'b');
axis square tight

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文