% Drawing example

% (c) 2012-02-26, Martin Matousek
% Last change: $Date::                            $
%              $Revision$

%% Init
if( ~exist( 'subfig', 'file' ) )
  addpath Tools
end

disp('Creating example figures ...')
close all

%% General (non-euclidean) 2D plot

subfig( 2, 3, 1 );

% Some data ...
t = 0:0.1:5.3; % [s]
g_earth = 9.81; % m/s^2
g_moon = 1.63; % m/s^2 
s_earth = 0.5 * g_earth * t.^2;
s_moon = 0.5 * g_moon * t.^2;

% Plot them

plot( t, s_earth, 'b', t, s_moon, 'k' );
axis tight 
xlabel( 'time [s]' )
ylabel( 'distance [m]' )
title('Free-fall trajectory comparison')
legend( 'Earth', 'Moon', 'location', 'northwest' )

%% Plot with bitmap image

subfig( 2, 3, 2 );

% Some data ...
r = rand( 1, 36 ) * 50 + 50; r = [r r(1)];
x = cos( linspace( 0, 2*pi, 37 ) ) .* r + 300;
y = sin( linspace( 0, 2*pi, 37 ) ) .* r + 200;

% Read and show the image
im = imread( 'daliborka_01.jpg' );
image( im );
hold on % next drawing commands are appended

% Draw some entities
h1 = plot( 100, 100, 'rx', 'linewidth', 2 );
h2 = plot( 200, 200, 'o', 'color', [ 1 1 0 ], 'linewidth', 2 );
h3 = plot( x, y, 'm.-' );
text( 641, 152, 'Tower', 'backgroundcolor', [1 1 0.8], ...
      'VerticalAlignment', 'bottom' ) 
h4 = plot( 641, 152, 'r.' );

hold off
axis image
legend( [h1 h2 h3 h4], 'A point', 'Also a point', 'Random polygon', ...
        'A point with label', ...
        'location', 'southeast' );
title( 'Daliborka' )

%% 3D euclidean plot

subfig( 2, 3, 3 );

X1 = rand( 3, 100 ) * 4 - 2; % random 3D points 
X2 = rand( 3, 50 ) * 0.2 - 0.1; % random 3D points 


plot3( [ 0 0 0; 1 0 0 ], [ 0 0 0; 0 1 0 ], [ 0 0 0; 0 0 1 ], 'k', ...
       'linewidth', 2 )
hold on
h1 = plot3( X1(1,:), X1(2,:), X1(3,:), 'r.' );
h2 = plot3( X2(1,:), X2(2,:), X2(3,:), 'b.' );

text( 1, 0, 0, '\delta_x' )
text( 0, 1, 0, '\delta_y' )
text( 0, 0, 1, '\delta_z' )
hold off
axis equal
grid on
xlabel( 'x [m]' );
ylabel( 'y [m]' );
zlabel( 'z [m]' );
title( 'Coordinate system delta and 3D points' );
legend( [h1 h2], 'Far points', 'Near points', 'location', 'southwestoutside' )

%% 3D euclidean plot - var 2

subfig( 2, 3, 6 );

% the same as above
plot3( [ 0 0 0; 1 0 0 ], [ 0 0 0; 0 1 0 ], [ 0 0 0; 0 0 1 ], 'k', ...
       'linewidth', 2 )
hold on
h1 = plot3( X1(1,:), X1(2,:), X1(3,:), 'r.' );
h2 = plot3( X2(1,:), X2(2,:), X2(3,:), 'b.' );

text( 1, 0, 0, '\delta_x' )
text( 0, 1, 0, '\delta_y' )
text( 0, 0, 1, '\delta_z' )
hold off
axis equal
grid on
xlabel( 'x [m]' );
ylabel( 'y [m]' );
zlabel( 'z [m]' );

% zoom
set( gca, 'xlim', [-0.3 0.3] );
set( gca, 'ylim', [-0.3 0.3] );
set( gca, 'zlim', [-0.3 0.3] );

title( 'Coordinate system delta and 3D points (zoom-in)' );



disp( 'Creating example figures: finished.' )
