% for inclusion in 3d graphics programs /RUN {} def RUN (../ps/mkpath.inc) run % [...] /parametrization t0 ti N % [x y z] -> [x/z y/z] /perspective-0-render { 1 dict begin /x exch def [ x 0 get x 2 get div x 1 get x 2 get div ] end } def % [[x y z] [x' y' z']] -> [[x/z y/z][(x/z)' (y/z)']] /perspective-1-render { 2 dict begin aload pop /v exch def /x exch def [ [ x 0 get x 2 get div x 1 get x 2 get div ] [ v 0 get x 2 get mul x 0 get v 2 get mul sub x 2 get dup mul div v 1 get x 2 get mul x 1 get v 2 get mul sub x 2 get dup mul div ] ] end } def % [x y z] -> [x y] /projection-0-render { 1 dict begin /x exch def [ x 0 get x 1 get ] end } def % [[x y z] [x' y' z']] -> [[x y][x' y']] /projection-1-render { % dup == 2 dict begin aload pop /v exch def /x exch def [ [ x 0 get x 1 get ] [ v 0 get v 1 get ] ] end } def % ------------------------------------------------------------- % M v /3Daffine { 3 dict begin /3Dv exch def aload pop /3DT exch def /3DM exch def [ 3DM 0 get 0 get 3Dv 0 get mul 3DM 0 get 1 get 3Dv 1 get mul add 3DM 0 get 2 get 3Dv 2 get mul add 3DT 0 get add 3DM 1 get 0 get 3Dv 0 get mul 3DM 1 get 1 get 3Dv 1 get mul add 3DM 1 get 2 get 3Dv 2 get mul add 3DT 1 get add 3DM 2 get 0 get 3Dv 0 get mul 3DM 2 get 1 get 3Dv 1 get mul add 3DM 2 get 2 get 3Dv 2 get mul add 3DT 2 get add ] end } def % M v /3Dmatrixvector { 2 dict begin /3Dv exch def /3DM exch def [ 3DM 0 get 0 get 3Dv 0 get mul 3DM 0 get 1 get 3Dv 1 get mul add 3DM 0 get 2 get 3Dv 2 get mul add 3DM 1 get 0 get 3Dv 0 get mul 3DM 1 get 1 get 3Dv 1 get mul add 3DM 1 get 2 get 3Dv 2 get mul add 3DM 2 get 0 get 3Dv 0 get mul 3DM 2 get 1 get 3Dv 1 get mul add 3DM 2 get 2 get 3Dv 2 get mul add ] end } def % ------------------------------------------------------------- % args: [location matrix + pars to drawing call + the parametrization] + t % output = [[X(t) Y(t)][X'(t) Y'(t)]] /projection-convert { 10 dict begin /t exch def /pars exch def /f pars 2 get cvx def /newpars pars 1 get def /locmat pars 0 get exch def /position newpars t f 0 get def /velocity newpars t f 1 get def /position locmat position 3Daffine def /velocity locmat 0 get velocity 3Dmatrixvector def [position velocity] projection-1-render end } def /perspective-convert { 10 dict begin /t exch def /pars exch def /f pars 2 get cvx def /newpars pars 1 get def /locmat pars 0 get exch def /position newpars t f 0 get def /velocity newpars t f 1 get def /position locmat position 3Daffine def /velocity locmat 0 get velocity 3Dmatrixvector def [position velocity] perspective-1-render end } def % /mkpolypath3d { 10 dict begin /N exch def /tf exch def /ti exch def /f exch def /pars exch def /locmat exch def [locmat pars f] convert ti tf N mkpolypath end } def /mkpath3d { 10 dict begin /N exch def /tf exch def /ti exch def /f exch def /pars exch def /locmat exch def [locmat pars f] convert ti tf N mkpath end } def % takes in an array of N 3D points /mkpolygon3d { 10 dict begin /p exch def /locmat exch def /N p length def N 2 lt { % no path } { % there is a path to be drawn thereisacurrentpoint { locmat p 0 get 3Daffine polygon3d-render aload pop lineto } { locmat p 0 get 3Daffine polygon3d-render aload pop moveto } ifelse 1 1 N 1 sub { /i exch def locmat p i get 3Daffine polygon3d-render aload pop lineto } for } ifelse end } def % ------------------------------------------------------- /use-perspective { /polygon3d-render /perspective-0-render cvx def /convert /perspective-convert def } def /use-projection { /polygon3d-render /projection-0-render cvx def /convert /projection-convert def } def % -------------------------------------------------------