[comp.lang.postscript] invertmatrix

don@brillig.umd.edu (Don Hopkins) (05/03/90)

In article <5903@amelia.nas.nasa.gov> izen@amelia.nas.nasa.gov (Prof. Steven H. Izen) writes:
>For those of you who have been trying to run escher.ps on NeWS on SGI
>machines and have been having trouble, the problem is that 4sight 1.4
>doesn't implement invertmatrix, so the ps program bombs when it isused.
>
>If anyone wants to implement a version of invertmatrix for us SGI users,
>please post it.
>-- 
>Steve Izen: {sun,uunet}!cwjcc!skybridge!izen386!steve  / Quote corner:
>or steve@izen386.math.cwru.edu                        / 
>or izen@cwru.cwru.edu	   /-------------------------/ My second bike is a car.
>                           | Klein bottle for sale - Inquire within.

Here is an implementation of "invertmatrix" written by Greg Couch. 
It's included in the collection of free NeWS software available via
anonymous ftp from tumtum.cs.umd.edu (128.8.128.49). 

	-Don

%!
% 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

gregc@cgl.ucsf.edu (Greg Couch) (05/03/90)

In article <5903@amelia.nas.nasa.gov> izen@amelia.nas.nasa.gov (Prof. Steven H. Izen) writes:
>If anyone wants to implement a version of invertmatrix for us SGI users,
>please post it.

I posted this before (April 1989) in comp.windows.news and since 4sight is
close to NeWS 1.1, this should work for SGI users too.

	- Greg Couch
	gregc@cgl.ucsf.edu

%!
% 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