I was wondering how I could create a picture of a flower in a plot. using only circles and ellipses. I wrote function files for both the circle and the ellipse already but don't know how to incorporate them together. function files included below

function [x,y] = ellipse(a,b)
theta = 0:0.1:2*pi
x = a*cos(theta);
y = b*sin(theta);
plot(x,y); axis('equal')
function [x,y] = circle(cx,cy,r,c)
theta = linspace(0,2*pi,100);
x = cx + r*cos(theta);
y = cy + r*sin(theta);
fill(x,y,c)

Answers (1)

Robert - I think that what you are missing from your ellipse function is an angle for the major (or minor) axis so that you can appropriately tilt your ellipsis). I see from your ellipse code that a intersection of the ellipse along the x-axis and b the intersection of the ellipse along the y-axis (assuming that the origin is at zero).
If we use the standard rotation matrix that does a counter-clockwise rotation about the origin, then we could modify your function to rotate the ellipse as follows
function [x,y] = ellipse(a,b,psi)
theta = 0:0.1:2*pi
x = a*cos(theta);
y = b*sin(theta);
R = [cos(psi) -sin(psi); sin(psi) cos(psi)];
% do the rotation
rXY = R*[x ; y];
rx = rXY(1,:);
ry = rXY(2,:);
% plot the rotated ellipse
plot(rx,ry); axis('equal')
The above will allow you to create an ellipse at any angle. The next step (of your homework) would then be to call this function multiple times with an appropriate angle so that you can create a number of ellipses around the origin (0,0) and so have the petals of a flower (though most likely, all "petals" will overlap). You can then use the circle function to colour the centre of the flower (again, centred at the origin).

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Asked:

on 30 Oct 2015

Answered:

on 30 Oct 2015

Community Treasure Hunt

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

Start Hunting!