How can I generate the data for an eight '8' draw?

Hello, I would like to know how to generate the data for the shape of an eight. I've been trying with some hysteresis functions but nothing gets me close really.
Thank you very much

 Risposta accettata

You can try with this:
t=0:.1:2*pi;
x = -sin(t);
y = sin(t);
plot(t,x,'*',t,y,'+')

2 Commenti

To see the 8 shape:
plot(x,t,'*',y,t,'+')
Thank you very much! It's kind of what I wanted.
Is there any easy way to extract the x and y datapoints for this figure?

Accedi per commentare.

Più risposte (2)

div = pi/50; % Resolution
sz = 100; % Number of Points in 2 Pi
th = zeros(1,sz);
th(1) = pi; % Starting at (0,0) and going up.
for i = 2:sz
th(i) = th(i-1)-div;
end
circ_x = fat*cos(th);
circ_y = fat*sin(th);
x1 = circ_x(1:26);
y1 = circ_y(1:26);
% -------------------------------------------
th(1) = 0;
for i = 2:sz*fat
th(i) = th(i-1)+div*fat;
end
cos_x = th;
cos_y = fat*cos(th/fat);
x2 = cos_x(1:51);
y2 = cos_y(1:51);
% -------------------------------------------
th(1) = -pi/2;
for i = 2:sz
th(i) = th(i-1)+div;
end
circ_x = fat*cos(th);
circ_y = fat*sin(th);
x3 = circ_x(1:51)+16;
y3 = circ_y(1:51);
% -------------------------------------------
x4 = x2';
x4 = flipud(x4);
x4 = x4';
y4 = y2';
y4 = flipud(y4);
y4 = -y4';
% -------------------------------------------
th(1) = -pi/2;
for i = 2:sz
th(i) = th(i-1)-div;
end
circ_x = fat*cos(th);
circ_y = fat*sin(th);
x5 = circ_x(1:26);
y5 = circ_y(1:26);
% -------------------------------------------
x = [x1 x2 x3 x4 x5];
y = [y1 y2 y3 y4 y5];
% A plot so you can see each section
figure
hold on
plot(x1,y1,'.r');
plot(x2,y2,'.b');
plot(x3,y3,'.k');
plot(x4,y4,'.g');
plot(x5,y5,'.y');
t = [0:0.001:10];
f = 10;
x = sin(2*pi*t*f);
y = sin(2*pi*t*2*f);
figure();
plot(x,y);

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by