Reputation: 374
I want to define a function that returns a circle with a given radius, center and filled color. My function now only returns a circle with a given radius and center but I do not know how to implement a variable that fills the circle with any given color. Here is the function code for the circle as is:
function h = circle(x,y,r)
hold on
th = 0:pi/100:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h=plot(xunit,yunit)
hold off
I think I need to change h=plot... to h=fill(xunit,yunit,'color') but I do not understand how. Any advice?
Upvotes: 0
Views: 112
Reputation: 699
Just do what you wrote. E.g.
h = fill(xunit, yunit, 'red');
It handles your circle as a polygon and fills it with red.
Upvotes: 2