Animation of rotating square in MATLAB
Code:
fill([-1
-1 1 1],[-1 1 1 -1],'k');
hold
on;
axis([-1
1 -1 1]);
pause(5);
t=0:pi/2:2*pi;
x=cos(t);
y=sin(t);
axis
equal;
hold
on;
for i=1:100
clf
fill([-1 -1 1 1],[-1 1 1 -1],'k');
axis([-1 1 -1 1]);
hold
on;
q=[x;y];
e=pi/10*i;
z=[cos(e)
-sin(e);sin(e) cos(e)];
k=z*q;
r=k(1,:);
d=k(2,:);
plot(r,d,'w','linewidth',5);
axis
square;
pause(0.2);
end
No comments