function [grid] = ppmakegridxy(cent,angle,spacing)
% Function PPMAKEGRIDXY.M
%
%    [grid] = ppmakegridxy(cent,angle,spacing)
%
%    PPMAKEGRIDXY creates a 25 x 25 grid of equally spaced points, using a
%    central point CENT, a tilt angle ANGLE and a point spacing SPACING.
%
%    [GRID] = PPMAKEGRID(CENT,ANGLE,SPACING) creates a [ 25 x 25 x 2 ]
%    array, GRID, that contains the location of each of the points:
%    GRID(:,:,1) contains the X coordinates and GRID(:,:,2) the Y
%    coordinates.  By definition, GRID(13,13,:) = CENT, since the points
%    are located by their distance from the central point.
%
%    All input variables must be specified; they are as follows:
%
%    CENT - the central point of the grid, CENT = [X Y].  Must be a 2x1
%    matrix.
%
%    ANGLE - the angle of the image tilt in radians.
%
%    SPACING - the mean point spacing in pixels.
%

    if nargin ~= 3
        error('Must specify all input variables: [grid] = ppmakegrid(cent,angle,spacing)') ;
    elseif nargout ~= 1
        error('Must specify all input variables: [grid] = ppmakegrid(cent,angle,spacing)') ;
    elseif ( length(cent) ~= 2 )
        error('CENT variable must be a 2x1 matrix with X and Y coordinates: CENT = [X Y]') ;
    end

%    Set up variables

    coords = [-12:1:12] ;
    horzdist = [spacing.*cos(angle) spacing.*sin(angle)] ;
    verdist = horzdist([2 1]) ;

%    Create spot matrix

    grid = zeros(25,25,2) ;

    for i = 1:25
        for j = 1:25
            grid(i,j,1) = cent(1) + ( horzdist(1).*coords(j) - verdist(1).*coords(i) ) ;
            grid(i,j,2) = cent(2) + ( horzdist(2).*coords(j) + verdist(2).*coords(i) ) ;
        end
    end

    return