% Question #2 - Solved using matlab

% Based on the notes linked off the webpage we were able to calculate 
% the necessary coordinates.  We used the equation provided under 
% Method I.  A is the large matrix, X is the solution matrix, H is our
% original transform matrix, vectorized (from x' = HX).

clear
clc

% since selection of world points is somewhat arbitrary so long as a
% geometry is maintained, we select: D = (-3, -2), A = (-3, 2), B = (3, 2)
% and C = (3, -2).  This makes P = (-3, 0), Q = (0, 0), R = (0, -2)
A = [-3 -2 1 0 0 0 0 0; 
      0 0 0 -3 -2 1 0 0; 
     -3 2 1 0 0 0 -1*-3 -1*2; 
      0 0 0 -3 2 1 -1*-3 -1*2; 
      3 2 1 0 0 0 -2*3 -2*2; 
      0 0 0 3 2 1 -1*3 -1*2; 
      3 -2 1 0 0 0 -3*3 -3 *-2; 
      0 0 0 3 -2 1 0 0];
  
X = [0 0 1 1 2 1 3 0]';

H = inv(A)*X;   % our transform matrix as a vector, h33 is presumed 1;

% make H a matrix
HM = [ H(1), H(2), H(3);
       H(4), H(5), H(6);
       H(7), H(8), 1];

P = [ -3 0 1]';
Q = [0 0 1]';

Pp = HM*P
Qp = HM*Q

% We note here that R's image coordinates will be 
% (Q's x image coordinate, D's y image coordinate) by the geometry of
% straight lines.
Rp = [Qp(1), 0, 1]