% Create a grid of x,y points for plotting wave functions of the Buminovich stadium.
%
% 2015-Dec-08  C. Kankelborg
function [x2d,y2d,x1d,y1d,mask] = gridpoints(dx,L)
% dx = isotropic grid resolution (end cap radius = 1).
% L = Stadium side length (end cap radius = 1).

% Create a regular grid of points on a rectangle that circumscribes the stadium. 
x1d = -(1+L/2):dx:(1+L/2); % 1D array of x values
y1d = -1:dx:1;             % 1D array of y values
Nx = numel(x1d);
Ny = numel(y1d);
x2d = ones(Ny,1) * x1d;   % 2D array of x values
y2d = y1d' * ones(1,Nx);  % 2D array of y values

% Identify interior vs. exterior points, and create mask
inside = find( abs(y2d)<1 & abs(x2d) < ( L/2 + sqrt(1 - y2d.^2) ) );
mask = zeros(size(x2d));
mask(inside) = 1;