%
% PURPOSE:  Create both a list of triples (x,y,z) defining the test map, and
%           a 2D matrix Z from the triples suitable for plotting with surf().
%
% CHANGELOG:  1) rsm; 22 June 2019. 35x35 tennis stadium.
%             2) rsm; 24 June 2019. Add floor at 50 depth extending 15 meters
%                                   outside stadium on all sides.
%
% NOTES: 1) The map coordinate system is NED at the surface, with x,y
%           centered in the stadium.  So, the dimensions below are symmetric
%           about the origin.
%
bottom    = [];
maxdepth  = 50;            %meters.  Depth of floor.
increment = 10;            %meters.  1/2 horiz size of floor inside stadium.
northing0 = 4062000;       %meters.  UTM nominal location at Portuguese Ledge.
easting0  = 594000;        %meters.  UTM nominal location at Portuguese Ledge.
mapEdge   = 50;            %meters.  Total map size is 2xedge, symmetric in
                           %         x and y.
stadiumWall = 35;          %meters.  Outside dimension of wall.
%
for( z = maxdepth:-1:20 )
  for( x = [-mapEdge:mapEdge ] )
    for( y = [-mapEdge:mapEdge ] )
      if( z < maxdepth )
	if( abs(x) < increment && abs(y) < increment || abs(x) > stadiumWall ...
	      || abs(y) > stadiumWall )
	  %We're either in the cavity, or outside the stadium.  
	  %Don't add points.
	else
	  bottom(end+1,:) = [x y z];
	  plg.z(x+mapEdge+1, y+mapEdge+1) = z;
	  plg.northings(x+mapEdge+1,1) = x;
	  plg.eastings(y+mapEdge+1,1) = y;
	end
      else
	bottom(end+1,:) = [x y z];
	plg.z(x+mapEdge+1, y+mapEdge+1) = z;
	plg.northings(x+mapEdge+1,1) = x;
	plg.eastings(y+mapEdge+1,1) = y;
      end
    end
  end
  increment = increment+1;
end

csvwrite('stadium.csv',bottom);
save('stadium','bottom','plg','x','y','z')
