how to fill color in 1/4 th circle

3 views (last 30 days)
Xiao yang
Xiao yang on 15 Jun 2024
Commented: Star Strider on 16 Jun 2024

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')

Answers (1)

Star Strider
Star Strider on 15 Jun 2024
Edited: Star Strider on 15 Jun 2024
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 Comments
Star Strider
Star Strider on 16 Jun 2024
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!