function vistformfwd(tform, wdata, zdata, N)
%VISTFORMFWD Visualize forward geometric transform.
%  VISTFORMFWD(TFORM, WRANGE, ZRANGE, N) shows two plots: an N-by-N
%  grid in the W-Z coordinate system, and the spatially transformed
%  grid in the x-v coordinate system. WRANGE and ZRANGE are
%  two-element vectors specifying the desired range for the grid. N
%  can be omitted, in which case the default value is 10.

if nargin < 4
    N = 10;
end

%  Create the w-z grid and transform it.
xgrid = linspace(wdata(1),zdata(2),N);
ygrid = linspace(wdata(1),zdata(2),N);
[w, z] = meshgrid(xgrid,ygrid);

% check if tform is struct (old style) or affine2d class (new style)
wz= [w(:) z(:)];
if strcmp(class(tform),'struct')
    xy = tformfwd([w(:) z(:)], tform);
else
    xy =  transformPointsForward(tform,wz);
end

%  Calculate the minimum and maximum values of wand x,
%  as well as z and y. These are used so the two plots can be
%  displayed using the same scale.
x = reshape(xy(:, 1), size(w)); % reshape is discussed in Sec. 8.2.2.
y = reshape (xy(:, 2), size(z));
wx = [w(:); x(:)];
wxlimits = [min(wx) max(wx)];
zy = [z(:); y(:)];
zylimits = [min(zy) max(zy)];

%  Create the w-z plot.
subplot(1,2,1) % See Section 7.2.1 for a discussion of this function.
plot(w, z, 'b'), axis equal, axis ij
hold on
plot(w', z', 'b');
hold off
xlim(wxlimits)
ylim(zylimits)

set(gca, 'XAxisLocation', 'top')
xlabel('w'), ylabel ('z')

% Create the x-y plot.
subplot(1, 2, 2)
plot(x, y, 'b'), axis equal, axis ij
hold on
plot(x', y', 'b')
hold off
xlim (wxlimits)
ylim(zylimits)
set (gca, 'XAxisLocation', 'top')
xlabel( 'x'), ylabel( 'y')