% - mkpath.inc ------------------------ % For a simple currentpoint: /pathcount { 0 {pop pop 1 add} {pop pop 1 add} {pop pop pop pop pop pop 1 add} {1 add} pathforall } def /thereisacurrentpoint { 0 pathcount ne {true} {false} ifelse } def % - for debugging ----------------------------- /pwd 0.032 def /pixel { 2 copy newpath moveto pwd 2 div neg pwd 2 div neg rmoveto pwd 0 rlineto 0 pwd rlineto pwd neg 0 rlineto 0 pwd neg rlineto closepath fill } def % --------------------------------------------- % stack: [parameters] /f t0 t1 N /mkpath { 12 dict begin /N exch def /t1 exch def /t exch def /f exch cvx def /pars exch def /h t1 t sub N div def /h3 h 0.333333 mul def pars t f aload pop /velocity exch def /position exch def position aload pop thereisacurrentpoint { lineto } { moveto } ifelse N { % x y = currentpoint % currentpoint pixel pop position 0 get velocity 0 get % x dx/dt h3 mul add position 1 get velocity 1 get % y dy/dt h3 mul add /t t h add def pars t f aload pop /velocity exch def /position exch def position 0 get velocity 0 get h3 mul sub position 1 get velocity 1 get h3 mul sub position 0 get position 1 get % pixel curveto } repeat end } def % An addition to the 2D drawing: produces a polygonal path % with exactly the same call as mkpath - for debugging % when you suspect your derivative formula is incorrect /mkpolypath { 10 dict begin /N exch def /tf exch def /ti exch def /f exch cvx def /pars exch def /h tf ti sub N div def pars ti f % [[x y][x' y']] 0 get aload pop thereisacurrentpoint { lineto } { moveto } ifelse /t ti h add def N { pars t f 0 get aload pop lineto /t t h add def } repeat end } def % pars /f ti tf N => a polygon of (N+1) points