% Simulated dataset of triangles randomly
% sampled around a baseline triangle
%
% Samuli Siltanen Nov 2015

% Parameters for controlling the plots
lwidth = .5;
msize  = 10;
fsize  = 16;

% Create a baseline triangle
blt = [0 sqrt(3) 1 0 -1 0];

% First: simulate the dataset with no variation
n = 100;
trdata = repmat(blt,n,1);

% Second: add random variation to the data
amplitude1 = 0.1;
amplitude2 = 0.6;
trdata(:,1) = trdata(:,1) + amplitude1*randn(size(trdata(:,1)));
trdata(:,2) = trdata(:,2) + amplitude2*randn(size(trdata(:,2)));
trdata(:,3) = trdata(:,3) + amplitude1*randn(size(trdata(:,3)));
trdata(:,4) = trdata(:,4) + amplitude1*randn(size(trdata(:,4)));
trdata(:,5) = trdata(:,5) + amplitude1*randn(size(trdata(:,5)));
trdata(:,6) = trdata(:,6) + amplitude1*randn(size(trdata(:,6)));

% Save the dataset to file
save triangledataset trdata

% Plot the baseline triangle with red vertices
figure(1)
clf
plot(...
    [blt(1) blt(3) blt(5) blt(1)],...
    [blt(2) blt(4) blt(6) blt(2) ],'k');
hold on
plot(...
    [blt(1) blt(3) blt(5) blt(1)],...
    [blt(2) blt(4) blt(6) blt(2) ],'r.');

% Plot the dataset triangles with blue vertices
for iii = 1:n
    curr_tr = trdata(iii,:);
    plot(...
        [curr_tr(1) curr_tr(3) curr_tr(5) curr_tr(1)],...
        [curr_tr(2) curr_tr(4) curr_tr(6) curr_tr(2) ],'b.','markersize',msize);
end
    
% Axis settings
axis equal
xdata = trdata(:,[1,3,5]);
ydata = trdata(:,[2,4,6]);
MINx = min(xdata(:));
MAXx = max(xdata(:));
MINy = min(ydata(:));
MAXy = max(ydata(:));
axis([MINx-.2 MAXx+.2 MINy-.2 MAXy+.2])