Making a simple flower

23 visualizaciones (últimos 30 días)
Gashi
Gashi el 6 de En. de 2022
Editada: KSSV el 7 de En. de 2022
I need to make the exact same flower like on the picture. Hope someone could help me out. Thank you!

Respuestas (3)

John D'Errico
John D'Errico el 6 de En. de 2022
Editada: John D'Errico el 6 de En. de 2022
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 comentarios
Gashi
Gashi el 6 de En. de 2022
Editada: Gashi el 6 de En. de 2022
Well I've got to do this for a project for my uni but we've never done anything in MATLAB, they just gave us some random page that has no info what so ever and said good luck hahah. I've been researching for 2 days but there is so little information about this topic or atleast I can't figure out where to find it.
However, I managed to come pretty close to a solution, but still can't manage to make it look like on the picture.
This is what I got:
clf
figure;
t=0:0.01:2*pi;
x=10*cos(t);
y=3*sin(t);
for i=1:12
hold on;
q=[x;y];
e=pi/12*i;
z=[cos(e) -sin(e);sin(e) cos(e)];
k=z*q;
r=k(1,:);
d=k(2,:);
plot(r,d);
axis square;
pause(1);
end
hold on;
drawCircle(0,0,1);
Steven Lord
Steven Lord el 6 de En. de 2022
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 (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB. One of the sections covers the basics of plotting data.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 6 de En. de 2022
See my ellipse demos and adapt as needed.

KSSV
KSSV el 7 de En. de 2022
Editada: KSSV el 7 de En. de 2022
@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] ;
figure
axis equal
hold on
plot(xc,yc)
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) ;
end
axis([-6 6 -6 6])
box on

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by