How to draw a white circle ?

Hello,
I would like to draw a white circle in a black square in Matlab but I don't have any idea how to do it. Would you please explain me how to do it ?
In advance, thank you !

 Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 29 Oct 2012
Edited: Azzi Abdelmalek on 29 Oct 2012
r=4; %radius
x0=0;y0=0; % circle center coordinates
x=x0-r:0.01:x0+r
y=sqrt(r^2-(x-x0).^2)+y0;
fill([x0-r x0+r x0+r x0-r ],[y0-r y0-r y0+r y0+r ],'k')
hold on;
plot(x,y,'w',x,-y,'w');
axis square
axis([x0-2*r x0+2*r y0-2*r y0+2*r]) % facultative

3 Comments

Thank you for your answer.
I could understand that the circle's equation is : y=sqrt(r^2-(x-x0).^2)+y0;
But I didn't understand this line : x=x0-r:0.01:x0+r
Would you please explain why did you write this ?
Thanks again !
Yes
fill([x fliplr(x)],[y fliplr(-y)],'w')
x=x0-r:0.01:x0+r
is a vector of points we are using to plot your circle

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 30 Oct 2012

0 votes

1 Comment

Thanks for the link ! I'll search in the FAQs the next time before asking any question ;)

Sign in to comment.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!