File Exchange

## Draw a filled circle

version 1.0 (2.04 KB) by

Plots a filled circle with given radius, center and color.

4.625
9 Ratings

Updated

FILLEDCIRCLE Filled circle drawing

filledCircle(CENTER,R,N,COLOR) draws a circle filled with COLOR that has CENTER as its center and R as its radius, by using N points on the periphery.

Usage Examples,

filledCircle([1,3],3,1000,'b');
filledCircle([2,4],2,1000,'r');

If you would like to generate the screenshot image above, you could do this:

filledCircle([1,3],3,100,'k');
hold on
filledCircle([-0.25,4.25],1,100,'r');
filledCircle([2.5,3],1,100,'g');
filledCircle([0.1,1.7],1,100,'b');
axis off

Best.

Todd LeBlanc

### Todd LeBlanc (view profile)

Thanks a lot for sharing your cleverness ...

Alex R.

### Alex R. (view profile)

I know this is old but I wanted to note that it can be done easier and faster as follows:

t = 2*pi/N*(1:N);
fill(c(1)+r*cos(t), c(2)+r*sin(t), color);

Also note that you don't need both 0 and 2pi (they are the same polar point). Your code actually generates N+1 points.

[ depending on N, the above can be substantially faster than using linspace() + ones() + pol2cart() ]

Alex.

David-Leon

### David-Leon (view profile)

This addon has a bug (I guess). It changes the aspect ratio of my plot.

Hi Irvin,

I am not sure I understand your question thoroughly but here is what you can do for transparency:

% Filled object becomes more and more transparent as the following variable [transp] goes to zero. [Max value is 1]
transp = 0.5;
set(h,'FaceAlpha',transp);

Best.

irvin rynning

### irvin rynning (view profile)

In the code using a white fill
h=fill(X,Y,'w');
results in the same circle with white center.
how to make it transparent ?

Aziz

### Aziz (view profile)

Hi Catalin,

You may want to check if you are playing with the axes, especially whether or not the code is making a zooming effect.

If you can't figure that out, using the clf command of matlab, or closing and reopening the figure window at each iteration should solve the problem.

Best.

AwedBy Matlab

### AwedBy Matlab (view profile)

Hi Sadik, I am having some problems using filledCircle - the first time I use the function to draw a couple of circles, they are displayed at a certain size, but then the second time (e.g. second iteration of a for loop) they are displayed slightly bigger, even though the function was called with the same RADIUS parameter. Do you know why that might be? Thanks very much!

AwedBy Matlab

### AwedBy Matlab (view profile)

Very useful, thank you!

Tima Tima

### Tima Tima (view profile)

Thank you for more simple and more useable code

##### MATLAB Release
MATLAB 7.10 (R2010a)
##### Acknowledgements

Inspired by: Draw a circle.

Inspired: circle plotter, circlem

Play today