%! % Date: Wed, 5 Apr 89 21:22:16 EDT % To: NeWS-makers@brillig.umd.edu % Subject: invertmatrix code supplied % From: gregc@cgl.ucsf.edu (Greg Couch) % % The following is PostScript source for the invertmatrix operator that % NeWS left out for some stupid reason. It even fails in the same ways % as the real PostScript version. Enjoy... % % The following is an implementation of the PostScript invertmatrix for NeWS. % No copyright allowed. Greg Couch, UCSF Computer Graphic Lab, April 1989 % % [ a b c d x y ] -> % [ d -b -c a (cy - dx) -(ay - bx) ] / (ad - bc) systemdict /invertmatrix known not { systemdict /invertmatrix { % matrix1 matrix2 invertmatrix matrix2 7 dict begin exch aload pop % m2 a b c d x y /y exch def /x exch def % m2 a b c d /d exch def /c exch def % m2 a b /b exch def /a exch def % m2 /t a d mul b c mul sub def % t = ad - bc d t div % m2 a2 b neg t div % m2 a2 b2 c neg t div % m2 a2 b2 c2 a t div % m2 a2 b2 c2 d2 c y mul d x mul sub t div % m2 a2 b2 c2 d2 x2 b x mul a y mul sub t div % m2 a2 b2 c2 d2 x2 y2 7 -1 roll % a2 b2 c2 d2 x2 y2 m2 astore % m2 end } put } if