Making a simple flower

26 次查看(过去 30 天)
编辑: KSSV ,2022-1-7
I need to make the exact same flower like on the picture. Hope someone could help me out. Thank you!

回答(3 个)

John D'Errico
John D'Errico 2022-1-6
编辑:John D'Errico 2022-1-6
What did you try? As it is, all we are asked to do is to write a complete code to solve your problem. And we don't do that here. (Since this is surely part of your homework or a student project of some sort.)
The solution is a simple one. Break ANY large problem down into small ones. Solve each small problem, one at a time. Then solve the large problem, by combining the small pieces into a whole. So...
  1. Write a code that will draw a circle of known radius and center in a figure.
  2. Write a code that will draw an ellipse, of known major and minor axes, at a given inclination and center, again, drawing the result in a figure.
  3. Finally, draw all 12 ellipses necessary, as well as the circle in one figure. Remember to use hold on to force the next curve to appear on the same set of axes.
(1) may be trivial for you, or possibly not. Only you know if that is true. In fact, a circle is just a simple version of an ellipse. So if you can solve the general ellipse problem, then you have solved the large part of this problem.
So if (2) is still too difficult, that is, to draw one ellipse, then break it down. First, find a reference that explains how to draw an ellipse. I would suggest looking for the equation of an ellipse in polar coordinates.
IF an inclined ellipse is too difficult at first, then figure out how to draw an ellipse that is NOT at an inclined angle. Then figure out how to rotate it. I'm sorry, but homework is designed to make YOU think, not for you to be given the answer on a platter.
  2 个评论
Steven Lord
Steven Lord 2022-1-6
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial ( to quickly learn the essentials of MATLAB. One of the sections covers the basics of plotting data.


Image Analyst
Image Analyst 2022-1-6
See my ellipse demos and adapt as needed.

KSSV 2022-1-7
编辑:KSSV 2022-1-7
@John D'Errico I have seen this question whence asked. Worked on it yesterday and could not upload that time and left home from office. As the answer was ready, I am answering it now.
% define angle
t = linspace(0,2*pi) ;
xc = cos(t) ; yc = sin(t) ;
% define ellipse centers
m = 12 ;
th = linspace(0,2*pi,m) ;
cx = 4.*cos(th) ;
cy = 4.*sin(th) ;
% Define ellipse
a = 2 ; b = 1/2 ;
xe = a*cos(t) ;
ye = b*sin(t) ;
P = [xe;ye] ;
axis equal
hold on
for i = 1:m
% Rotation matrix
R = [cos(th(i)) -sin(th(i)) ;
sin(th(i)) cos(th(i))] ;
% Rotate the ellipse
Pr = R*P ;
x = cx(i)+Pr(1,:) ;
y = cy(i)+Pr(2,:) ;
% plot ellipse
plot(x,y) ;
axis([-6 6 -6 6])
box on


Community Treasure Hunt

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

Start Hunting!

Translated by