% Use of GAMS/Matlab interface to display optimal polygon

% initial set up; clear current figures and set gams output to vector form
close;
clear gamso;
gamso.output = 'std';
gamso.compress = 'true';
gamso.form = 'full';
gamso.type = 'parameter';

% matlab file for plotting optimal polygon of radius 1
n = input('Dimension of polygon = ');
commandstr = sprintf('ngon --n=%d',n);
ngon_coords = gams(commandstr);

% transfer to X and Y matrices
X = ngon_coords(:,1); Y = ngon_coords(:,2);

% plot it in a nice color, using ColorSpec's RGB array
fill(X,Y,[1 0 1]);

% use a random color instead;
% fill(X,Y,[.5 .5 .5] + .5*rand(1,3));
hold on;
% Now plot vertices on top
scatter(X,Y);

% give it a title (specify number of vertices)
title(['Optimal Polygon with ',num2str(size(X,1)),' Vertices and Diameter 1']);

% figure the range, making sure the area is square to prevent distortion
xmin = min(X); xmax = max(X); xmid = (xmax+xmin)/2; xdiff = xmax-xmin;
ymin = min(Y); ymax = max(Y); ymid = (ymax+ymin)/2; ydiff = ymax-ymin;

diff = 1.2 * max([xdiff  ydiff]);
xmin = xmid - diff/2; xmax = xmid + diff/2;
ymin = ymid - diff/2; ymax = ymid + diff/2;

axis([xmin xmax ymin ymax]);

% need this to ensure that the area plotted is indeed square
axis square;
