%Writen by Anthony Ripa for HW4c

'start'

world = [0,2,2,0,1,1;
    0,0,3,3,2,1;
    2,2,2,2,1,1;
    1,1,1,1,1,1]

mym = [1,0,0,0;0,1,0,0;0,0,1,0;0,0,1,0]

myscreen = mym * world

for i=1:6
   myscreen(:,i)=myscreen(:,i)/myscreen(4,i);
end
TheScreenPointsImLookingForAtEnd = myscreen

a = []
for i = 1:6
            psx = myscreen(1,i);
            psy = myscreen(2,i);
            x = world(1,i);
            y = world(2,i);
            z = world(3,i);
            myrow1 = [0 0 0 0 x y z 1 -x*psy -y*psy -z*psy -psy];
            myrow2 = [-x -y -z -1 0 0 0 0 x*psx y*psx z*psx psx];
            a=[a;myrow1;myrow2];
end

a
[u,s,v] = svd(a);            
m = v(:,12)
m = reshape(m,4,3)'

screencheck = m * world;

for i=1:6
   screencheck(:,i)=screencheck(:,i)/screencheck(3,i);
end

TheScreenPointsIGetAtEnd = screencheck