Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

creating a circle in Matlab...

4,896 views
Skip to first unread message

luca.pa...@gmail.com

unread,
Nov 14, 2007, 12:08:07 PM11/14/07
to
Hi everyone,

I have a 128 X 128 matrix that represents an image.

What I want to do is create a filled circle in the matrix with the
center at a given point and of a given radius and filled with a given
value.

What is the easiest way to do something like this?

Cheers,
Luc

Peter Boettcher

unread,
Nov 14, 2007, 12:18:00 PM11/14/07
to
luca.pa...@gmail.com writes:

Generate two matrices of coordinates x and y. Then operate on those
coordinates to produce whatever you want. In this case, calculate the
distance from your point. If that distance is < R, the point is inside
the circle. Etc.

[x y] = meshgrid(1:128, 1:128);

imagesc(x)
imagesc(sqrt(x.^2 + y.^2))
imagesc(sqrt((x-64).^2 + y.^2))

etc.


-Peter

Vikas Mehta

unread,
Nov 21, 2007, 4:22:33 PM11/21/07
to
Peter Boettcher <boet...@ll.mit.edu> wrote in message
<muyabpg...@G99-Boettcher.llan.ll.mit.edu>...

hi,
i have the following matlab code to draw a circle. I want
to know how i can fill the circle with black.

t = linspace(0,2*pi,1000);
h=0;
k=0;
r=10;
x = r*cos(t)+h;
y = r*sin(t)+k;
plot(x,y);
axis square;


I also want to know how i can cut the circle in such a way
that the four quarters of the circle which are black in
color move to the corners.

Thanks,
Vikas

Walter Roberson

unread,
Nov 21, 2007, 7:53:54 PM11/21/07
to
In article <fi27ip$2s3$1...@fred.mathworks.com>,
Vikas Mehta <gets...@yahoo.co.in> wrote:

>i have the following matlab code to draw a circle. I want
>to know how i can fill the circle with black.

>t = linspace(0,2*pi,1000);
>h=0;
>k=0;
>r=10;
>x = r*cos(t)+h;
>y = r*sin(t)+k;
>plot(x,y);
>axis square;

Instead of plot(x,y), fill(x,y,'k')
--
"Okay, buzzwords only. Two syllables, tops." -- Laurie Anderson

RazvanStef...@gmail.com

unread,
Jan 10, 2008, 11:45:23 AM1/10/08
to comp.soft-...@groups.google.ca
Hi!

In Matlab there is a function Delaunay to construct the Delaunay Graph
of a 2 dimension set of points. Does anyone have/know how to compute
the source code for drawing the Gabriel Graph using Matlab?


The Gabriel graph of a set P of points in the plane is defined as
follows: Two points p and q are connected by an edge of the Gabriel
graph if and only if the circle with diameter pq does not contain any
other point of P in its interior.

someone

unread,
Jan 10, 2008, 12:35:06 PM1/10/08
to
luca.pa...@gmail.com wrote in message
<1195060087.6...@50g2000hsm.googlegroups.com>...

Believe it or not, you actually use the MATLAB rectangle
command to draw circles. The following code will draw a
circle of radius 3 centered at x=0 & y=0:

>> radius = 3;
>> w = radius;
>> h = radius;
>> x = 0;
>> y = 0;
>> rectangle('Position',[x,y,w,h],'Curvature',[1,1])
>>


someone

unread,
Jan 10, 2008, 12:43:01 PM1/10/08
to
"someone " <som...@somewhere.net> wrote in message
<fm5l0a$rp4$1...@fred.mathworks.com>...

Oops... Forgot the last part of your question.

To fill the above circle with green, use:

rectangle('Position',[x,y,w,h],'Curvature',

[1,1],'FaceColor','g'))

somayeh.she...@gmail.com

unread,
Sep 16, 2013, 2:44:17 AM9/16/13
to
hi- you said that " In this case, calculate the
distance from your point. If that distance is < R, the point is inside
the circle." i want to do like this but dont know how...:(
0 new messages