% uses Strang's house figure to show trans,..caffine,..biquadratic

hx=[-6 -6 -7 0 7 6  6 -3 -3  0  0 -6];
hy=[ -7  2  1 8 1 2 -7 -7 -2 -2 -7 -7];
h=hx+i*hy;

%figure
clg
%hx=[-9 -9 -10 0  10 9  9 -3.5 -3.5  0  0 -9 NaN -.5  -.5   NaN -7 -7 -5 -5 -7 NaN -3 -3 -1 -1 -3 NaN 1 1 3 3 1 NaN 5 5 7 7 5 NaN -7 -7 -5 -5 -7 NaN -3 -3 -1 -1 -3 NaN 1 1 3 3 1 NaN 5 5 7 7 5];
%hy=[-8  7  6  16  6 7 -8 -8    -1  -1 -8 -8 NaN -4.5 -3.5 [NaN  5  7  7  5  5 NaN  5  7  7  5  5 NaN 5 7 7 5 5 NaN 5 7 7 5 5 NaN  1  3  3  1  1 NaN  1  3  3  1  1 NaN 1 3 3 1 1 NaN 1 3 3 1 1]-.5];
% need more than endpoints when lines curve
roofx=[linspace(-10,0) linspace(0,10)];
roofy=[linspace(6,16)  linspace(16,6)];
doorx=[-3.5 -3.5   0  0 NaN -.5  -.5];
doory=[-8    -1   -1 -8 NaN -4.5 -3.5];
%facex=[9  9 -9 -9];
%facey=[7 -8 -8  7];
%face wasn't curved for bilinear, but is for pseudop...
facex=[linspace(9,9)  linspace(9,-9)  linspace(-9,-9)];
facey=[linspace(7,-8) linspace(-8,-8) linspace(-8,7)];
windowsx=[-7 -7 -5 -5 -7 NaN -3 -3 -1 -1 -3 NaN 1 1 3 3 1 NaN 5 5 7 7 5 NaN -7 -7 -5 -5 -7 NaN -3 -3 -1 -1 -3 NaN 1 1 3 3 1 NaN 5 5 7 7 5];
windowsy=[ 5  7  7  5  5 NaN  5  7  7  5  5 NaN 5 7 7 5 5 NaN 5 7 7 5 5 NaN  1  3  3  1  1 NaN  1  3  3  1  1 NaN 1 3 3 1 1 NaN 1 3 3 1 1]-.5;
hx=[windowsx NaN doorx NaN facex NaN roofx];
hy=[windowsy NaN doory NaN facey NaN roofy];

% original
h=hx+i*hy;
%subplot(221);plot(h);axis('image');title('original')
figw=1/7; %  7 figures; each 1/7 of total unit width
handle=axes('position',[0*figw .33 figw .33]);plot(h);axis('image');
set(handle,'visible','off')
xlabel('(ORIGINAL)')

H=[hx;hy];

% affine
A=[.9 .1;.5 .9];
G=A*H;
haffine=G(1,:)+i*G(2,:);
%subplot(222);plot(ga);axis('image');title('affine')
handle=axes('position',[1*figw .33 figw .33]);plot(haffine);axis('image');
set(handle,'visible','off')
xlabel('(AFFINE)')

% bilinear
pux=1; puy=0; puxy=0; pu=0;
pvx=0; pvy=1; pvxy=-.05; pv=0;
gx=pux*hx + puy*hy + puxy*hx.*hy +pu*ones(size(hx));
gy=pvx*hx + pvy*hy + pvxy*hx.*hy +pv*ones(size(hx));
hbilinear=gx+i*gy;
%subplot(223);plot(g);axis('image');title('bilinear')
handle=axes('position',[2*figw .33 figw .33]);plot(hbilinear);axis('image');
set(handle,'visible','off')
xlabel('(BILINEAR)')

% projective
% for corr2p:
x=[-7 -7  7  7];
y=[ 1  3  1  3];
u=[-7 -7  7  7];
v=[ 0  4  1  3];
[a b c d e f g h]=corr2p(x,y,u,v);
G=[a b c;d e f;g h 1]*[H;ones(1,length(H))]; % assume H at least 2 wide
gx=G(1,:)./G(3,:);
gy=G(2,:)./G(3,:);
hp=gx+i*gy;
%subplot(224);plot(g);axis('image');title('p-chirp')
handle=axes('position',[3*figw .33 figw .33]);plot(hp);axis('image');
%set(h,'Box','off')
%set(h,'linewidth',0)
% set(h,'ticklength',[0,0]) % not needed
%set(h,'xtick',NaN) % get rid of numbers
%set(h,'ytick',NaN) % get rid of numbers
set(handle,'visible','off') % turns off all but plot.
xlabel('(PROJECTIVE)')

% relative-projective
% for corr2p:
x=[-7 -7  7  7];
y=[ 1  3  1  3];
u=[-7 -7  9  9];
v=[ 0  3  1  3];
[a b c d e f g h]=corr2p(x,y,u,v);
G=[a b c;d e f;g h 1]*[H;ones(1,length(H))]; % assume H at least 2 wide
gx=G(1,:)./G(3,:);
gy=G(2,:)./G(3,:);
gx=gx-.5*H(1,:); % of the form (ax+b)/(cx+1)-x     % relative in x
gy=gy-.5*H(2,:);                                   % relative in y
hp=gx+i*gy;
handle=axes('position',[4*figw .33 figw .33]);plot(hp);axis('image');
set(handle,'visible','off') % turns off all but plot.
xlabel('(RELATIVE-PROJECTIVE)')

% pseudoperspective
pux=1; puy=0; pu=0; p=-.045;
pvx=0; pvy=1; pv=0; q=.00;
gx=pux*hx + puy*hy + pu*ones(size(hx)) + p*hx.*hx + q*hx.*hy; 
gy=pvx*hx + pvy*hy + pv*ones(size(hx)) + p*hx.*hy + q*hy.*hy;
hpp=gx+i*gy;
%subplot(223);plot(g);axis('image');title('pseudoperspective')
handle=axes('position',[5*figw .33 figw .33]);plot(hpp);axis('image');
set(handle,'visible','off')
xlabel('(PSEUDOPERSPECTIVE)')

% q-chirp (e.g. biquadratic)
pux=1; puy=0; puxy=0; puxx=-.03; pu=0;
pvx=0; pvy=1; pvxy=0; pvyy=0; pv=0;
gx=pux*hx + puy*hy + puxy*hx.*hy +puxx*hx.*hx +pu*ones(size(hx));
gy=pvx*hx + pvy*hy + pvxy*hx.*hy +pvyy*hy.*hy +pv*ones(size(hx));
hqchirp=gx+i*gy;
%subplot(223);plot(g);axis('image');title('q-chirp')
handle=axes('position',[6*figw .33 figw .2]);plot(hqchirp);axis('image');
set(handle,'visible','off')
xlabel('(BIQUADRATIC)')

