% triangle_plot.m
% Make some plots involving a triangle.
%
%  Plot 1: 
%  Try to plot a triangle.
%  It has three corners, so this should be easy.
%
txlist = [ 0.0, 2.0, 1.0 ];
tylist = [ 0.0, 1.0, 3.0 ];
plot ( txlist, tylist, 'LineWidth', 3 );
grid on
title ( 'triangle\_plot1: Bad Triangle plot()', 'FontSize', 24 );
xlabel ( '<-- X -->' );
ylabel ( '<-- Y -->' );
axis equal
print ( '-djpeg', 'triangle_plot1.jpg' );
pause
fprintf ( 'Press RETURN for next plot:\n' );
%
%-------------------------------------------------------------------------------
%  LESSON:
%  To PLOT a triangle, you need to list the first point again as the last point.
%  To PLOT ANY shape, you need to list the first point again as the last point.
%-------------------------------------------------------------------------------
%
%  Plot 2: 
%  To plot a triangle, you have to get BACK to the first point.
%
txlist = [ 0.0, 2.0, 1.0, 0.0 ];  % Repeated x coordinate of first point.
tylist = [ 0.0, 1.0, 3.0, 0.0 ];  % Repeated y coordinate of first point.
plot ( txlist, tylist, 'LineWidth', 3 );
grid on
title ( 'triangle\_plot2: Good Triangle plot()', 'FontSize', 24 );
xlabel ( '<-- X -->' );
ylabel ( '<-- Y -->' );
axis equal
print ( '-djpeg', 'triangle_plot2.jpg' );
pause
fprintf ( 'Press RETURN for next plot:\n' );
%
%  Plot 3: 
%  To plot a triangle and a square (fails).
%
txlist = [ 0.0, 2.0, 1.0, 0.0 ];
tylist = [ 0.0, 1.0, 3.0, 0.0 ];
plot ( txlist, tylist, 'LineWidth', 3 );
sxlist = [ 0.0, 1.0, 1.0, 0.0, 0.0 ];
sylist = [ 0.0, 0.0, 1.0, 1.0, 0.0 ];
plot ( sxlist, sylist, 'LineWidth', 3 );
grid on
title ( 'triangle\_plot3: Triangle plot() + Square Plot (oops)', 'FontSize', 24 );
xlabel ( '<-- X -->' );
ylabel ( '<-- Y -->' );
axis equal
print ( '-djpeg', 'triangle_plot3.jpg' );
pause
fprintf ( 'Press RETURN for next plot:\n' );
%
%-------------------------------------------------------------------------------
%  A PLOT command will wipe out the previous graph.
%  To plot TWO (or more) things, you can either
%  * make one "giant" plot command listing each set of data,
%  OR
%  * plot the first thing, say "hold on", issue more plots, then say "hold off".
%-------------------------------------------------------------------------------
%
%  Plot 4: 
%  To plot a triangle and a square with ONE plot command.
%
txlist = [ 0.0, 2.0, 1.0, 0.0 ]; 
tylist = [ 0.0, 1.0, 3.0, 0.0 ];
sxlist = [ 0.0, 1.0, 1.0, 0.0, 0.0 ];
sylist = [ 0.0, 0.0, 1.0, 1.0, 0.0 ];
plot ( txlist, tylist, ...
       sxlist, sylist, 'LineWidth', 3 );
grid on
title ( 'triangle\_plot4: plot ( Triangle + Square )', 'FontSize', 24 );
xlabel ( '<-- X -->' );
ylabel ( '<-- Y -->' );
axis equal
print ( '-djpeg', 'triangle_plot4.jpg' );
pause
fprintf ( 'Press RETURN for next plot:\n' );
%
%  Plot 5: 
%  To plot a triangle, hold on, plot square, hold off.
%
txlist = [ 0.0, 2.0, 1.0, 0.0 ];
tylist = [ 0.0, 1.0, 3.0, 0.0 ];
plot ( txlist, tylist, 'LineWidth', 3 );
sxlist = [ 0.0, 1.0, 1.0, 0.0, 0.0 ];
sylist = [ 0.0, 0.0, 1.0, 1.0, 0.0 ];
hold on
plot ( sxlist, sylist, 'LineWidth', 3 );
hold off
grid on
title ( 'triangle\_plot5: triangle + hold on + square + hold off )', 'FontSize', 24 );
xlabel ( '<-- X -->' );
ylabel ( '<-- Y -->' );
axis equal
print ( '-djpeg', 'triangle_plot5.jpg' );
pause
fprintf ( 'Press RETURN to finish:\n' );