% demos from Ch 13 & 14. Math 11. Barnett 9/12/10

% plot a line in 3d, 13.5
v = [1,2,3]; r0 = [3,2,1];
t = 0:1;
plot3(r0(1)+t*v(1),r0(2)+t*v(2),r0(3)+t*v(3));
xlabel('x'); ylabel('y'); zlabel('z'); axis vis3d

% check line at intersection of two planes, example 13.5.7b
figure; showplane([1 1 1], -1); hold on; showplane([1 -2 3], -1); % note -d !
v = [5,-2,-3]; r0 = [1,0,0]; t = 0:1; plot3(r0(1),r0(2),r0(3),'.'); % point
plot3(r0(1)+t*v(1),r0(2)+t*v(2),r0(3)+t*v(3));
xlabel('x'); ylabel('y'); zlabel('z'); axis vis3d; axis equal;
set(gcf, 'Renderer','OpenGL'); % makes z-buffer work so planes intersect right

% plot twisted cubic 14.1
t=-1:0.01:1;
figure; plot3(t, t.^2, t.^3);
xlabel('x'); ylabel('y'); zlabel('z'); axis vis3d

% plot trefoil knot 14.1
t=0:0.01:4*pi;
figure; plot3((2+cos(3*t/2)).*cos(t), (2+cos(3*t/2)).*sin(t), sin(3*t/2));
xlabel('x'); ylabel('y'); zlabel('z'); axis equal vis3d
