how to fill color in 1/4 th circle

3 次查看(过去 30 天)

clear
syms x
figure
fun = sqrt(2*x-x.^2);
fplot(fun,[0,2.2]);
hold on
y1 = [0 1 0 0];
x1 = [0 1 1 0];
fill(x1,y1,'y');
hold on
x2 = 1:0.01:2;
y2 = sqrt(2*x2-x2.^2);
fill([x2,fliplr(x2)],[y2,fliplr(y2)],'r')

回答(1 个)

Star Strider
Star Strider 2024-6-15
编辑:Star Strider 2024-6-15
A new function in R2024a is the polarregion function.
Try this —
figure
thetas1 = [0.5 1]*pi;
radii1 = [1 2];
polarregion(thetas1, radii1, 'FaceColor','y')
hold on
thetas2 = [0 0.5]*pi;
radii2 = [1 2];
polarregion(thetas2, radii2, 'FaceColor','r')
hold off
Ax = gca;
Ax.ThetaLim = [0 180];
Ax.RLim = [1 2];
Also see PolarAxes Properties for those details.
Doing it without using any of the polar functions is also straightforward, although easier using trigonometric functions,
Try this —
r1 = 1;
th1 = linspace(0, 90);
xy1 = [1+r1*cosd(th1); 1+r1*sind(th1)];
r2 = 1;
th2 = linspace(90, 180);
xy2 = [1+r2*cosd(th2); 1+r2*sind(th2)];
figure
patch([1 xy1(1,:)], [1 xy1(2,:)], 'r', 'EdgeColor','none' )
hold on
patch([1 xy2(1,:)], [1 xy2(2,:)], 'y', 'EdgeColor','none')
hold off
axis('equal')
Ax = gca;
Ax.Visible = 0;
Make appropriate changes to get the result you want.
.
EDIT — (15 Jun 2024 at 14:38)
Added second plot using the patch function.
.
  10 个评论
Star Strider
Star Strider 2024-6-16
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by