clear all;

figure;
view ([54.332, 33.734]);
daspect ([1, 1, 1]);
xlabel ('x');
ylabel ('y');
ylim ([-1.1, 1.1]);
xlim ([-0.1, 1.1]);
zlim ([-1.1, 1.1]);
grid on;
hold on;

for i = 0 : 100

  phi = 2 * pi () * i / 100;
  sp = sin (phi);
  cp = cos (phi);

  % The four vertices in Cartesian coordinates
  p1 = [0, 0, 0];
  p2 = [1, 0, 0];
  p3 = [1, 1, 0];
  p4 = [0, cp, sp];

  % Transform to patch data
  px = [p1(1); p2(1); p3(1); p4(1)];
  py = [p1(2); p2(2); p3(2); p4(2)];
  pz = [p1(3); p2(3); p3(3); p4(3)];

  cla;

  patch (px, py, pz, ones (size (px)));

  line ('xdata', [p1(1); p2(1)], 'ydata', [p1(2); p2(2)], ...
        'zdata', [p1(3); p2(3)], 'color', 'r');
  line ('xdata', [p2(1); p3(1)], 'ydata', [p2(2); p3(2)], ...
        'zdata', [p2(3); p3(3)], 'color', 'r');
  line ('xdata', [p3(1); p4(1)], 'ydata', [p3(2); p4(2)], ...
        'zdata', [p3(3); p4(3)], 'color', 'r');
  line ('xdata', [p4(1); p1(1)], 'ydata', [p4(2); p1(2)], ...
        'zdata', [p4(3); p1(3)], 'color', 'r');

  str = sprintf ('%1.0f', phi * 360 / (2 * pi ()));
  title (str);

  drawnow;
  pause (0.1);

end
