Educational materials

MATLAB: drawCircle

Credit: Dr. Pat Flynn

Source Code

function b = drawCircle(xc, yc, rad, col)
%   usage:      h = drawCircle (xc, yc, r)
%   alternate:   h = drawCircle (xc, yc, r, ‘color’)
%   purpose:   Draws a filled circle centered at (xc, yc) in drawing coordinates, and
%               with a radius of r in drawing coordinates. Returns a handle to the 
%               circle being created.  If present, col specifies the color of the circle.  If 
%               not specified, red will be used.
%

i = sqrt(-1);
c = plot(exp(i*[0:pi/100:2*pi])*rad + xc + yc*i);

xd = get(c, 'xdata');
yd = get(c, 'ydata');

set(c, 'Visible', 'off');

if (nargin < 4)
    col = 'red';
end

b = fill(xd, yd, col, 'EdgeColor', col);
set(b, 'Erase', 'xor')
set(b, 'Linewidth', 1)
r1 - 18 Sep 2007 - 18:53:36 - AaronStriegel
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Syndicate this site RSSATOM