How can I fill with color a odd flower in a cartesian o polar coordinates?

4 ビュー (過去 30 日間)
Marcos Perez
Marcos Perez 2015 年 7 月 8 日
回答済み: Adam Danz 2025 年 9 月 30 日
% In rectangular coordinates
theta=linspace(0,2*pi,200);
radius=cos(5*theta);
x=radius.*(cos(theta));
y=radius.*(sin(theta));
fill(x,y,'b') % when matlab run, only fill with color not odd flowers
axis('square')
% In polar coordinates
p=Polar(theta,radius,'-b')
patch(get(ph,'XData'), get(ph,'YData'), 'b')
  1 件のコメント
Image Analyst
Image Analyst 2015 年 7 月 8 日
I fixed your formating, and am attaching the screenshot you forgot to include:

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

採用された回答

bio lim
bio lim 2015 年 7 月 8 日
編集済み: bio lim 2015 年 7 月 8 日
As a matter of fact, you are filling with color. What you are filling are the small polygons as shown in the figure below.
If we look closely, we can see the small polygons that are filled with blue colour.
The fill() and patch() works perfectly when you are dealing with even number of petals. However, even for even petals, if you zoom in closely at the center, you can see that there are regions which are not filled.
I think the problem with your code is that when the radius takes less than 0 value, the polygons occur. So a simple solution would be:
theta=linspace(0,2*pi,200);
radius=cos(5*theta);
radius(radius <= 0) = 0;
x=radius.*(cos(theta));
y=radius.*(sin(theta));
fill(x,y, 'b');
axis('square')
Here is the updated graph.

その他の回答 (1 件)

Adam Danz
Adam Danz 2025 年 9 月 30 日
Starting in R2025a, polar axes support patch and surface objects.
Here's @bio lim's example applied to polar axes.
There's more info about patch and surface support in polar axes in the Graphics and App Building blog.
theta=linspace(0,2*pi,200);
radius=cos(5*theta);
radius(radius <= 0) = 0;
pax = polaraxes();
patch(pax,theta,radius,'blue',FaceAlpha=0.5)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by