%% Demo: random points on a plane in 3D

a1 = [1 2 6];
a2 = [-1 1 -1];
q = [1 1 1];

figure(1); clf;
lw = 'linewidth';
plot3([0 q(1)], [0 q(2)], [0 q(3)], 'b-', lw, 3);
hold on
plot3([0 a1(1)]+q(1), [0 a1(2)]+q(2), ...
      [0 a1(3)]+q(3), 'r-', lw, 3);
plot3([0 a2(1)]+q(1), [0 a2(2)]+q(2), ...
      [0 a2(3)]+q(3), 'g-', lw, 3);

axis equal
grid on

xlabel('x'); ylabel('y');  zlabel('z');

for i=1:1000
  % two random scalars between -2 and 2
  s = 4*rand()-2;
  t = 4*rand()-2;
  x = q + s*a1 + t*a2;
  plot3(x(1), x(2), x(3), 'k.', lw, 4)
  drawnow()
end
