% matlab file for plotting optimal polygon of radius 1 load ngon_coords.dat; % transfer to X and Y matrices X = ngon_coords(:,1); Y = ngon_coords(:,2); N = size(X,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; % now plot it as slices of pie, centered at (xmid,ymid) % first construct the matrices the define each wedge Xplot = zeros(3,N); Yplot = zeros(3,N); Xplot(1,:) = xmid; Yplot(1,:) = ymid; for i=1:N-1, Xplot(2,i) = X(i); Xplot(3,i) = X(i+1); Yplot(2,i) = Y(i); Yplot(3,i) = Y(i+1); end Xplot(2,N) = X(N); Xplot(3,N) = X(1); Yplot(2,N) = Y(N); Yplot(3,N) = Y(1); % now plot a wedge at a time, using "patch" to avoid deleting earlier % plots for i=1:N, patch(Xplot(:,i), Yplot(:,i), [.2 0 0] + (i/N)*.8*[1 0 0]); end axis([xmin xmax ymin ymax]); axis square; % try: fiddling with "rand" and the "central" color % to give darker/lighter/redder colors % give it a title (specify number of vertices) title(['Optimal Polygon with ',num2str(size(X,1)),' Vertices and Radius 1']);