function A= affine_transform(p, q)
% function A= affine_transform(p, q)
%
% Given two sets of points p and q, it estimates the
% affine transform q = R p + c via the least squres method.
% 
% p, q:  d x n matrix of d-dimensional points
% A =  [ R          c]
%        [  0,...,0  1]
%  The affine matrix is of size (d+1)x(d+1)
%
%
%  (C) 2008. Moo K. Chung   mkchung@wisc.edu
% University of Wisconsin-Madison
% October 5, 2012

d=size(p,1);
n= size(p,2);

P=[p; ones(1,n)];

Rc = q*P'*inv(P*P');

A=[Rc; [zeros(1,d) 1]];






