Article View: comp.lang.postscript
Article #4326Re: What does concat do?
From: Kenneth Porter
Date: Tue, 25 Dec 1990 00:18
Date: Tue, 25 Dec 1990 00:18
72 lines
2520 bytes
2520 bytes
For those without the Red Book (page 64):
PostScript's coordinate transformations are based on the idea
of a transformation matrix. In a 2-dimensional system, 6
numbers can describe all linear transformations of a
2-dimensional vector. Given a matrix [a b c d tx ty] and a
coordinate pair (x y), a transformed point (newx newy) can be
calculated with:
newx = a*x + c*y + tx
newy = b*x + d*y + ty
For normal operations, you can think of (x y) as user-space
coordinates, and (newx newy) as the device coordinates.
Numerous operators work on matrices; some operate on the
currentmatrix which transforms user coordinates into device
coordinates.
Examples of the former are matrix (creates an indentity
matrix), concatmatrix (three arguments, multiplies two matrices
together, putting the result in the third, returns the third),
and invertmatrix.
Examples of the latter are scale, translate, rotate, and
concat.
The concat operator concatenates its argument with the
currentmatrix (ie. the currentmatrix is changed to the argument
times the old currentmatrix). This is more efficient than
using separate translate, rotate, and scale operations. It
also allows skewing, for which there is no builtin operator.
Here's a definition of translate:
/translate {
/ty exch def % get y-translation
/tx exch def % get x-translation
/tmp-matrix matrix def % create identity matrix
tmp-matrix 4 tx put
tmp-matrix 5 ty put
tmp-matrix concat
} def
Here's a definition of scale:
/scale {
/sy exch def % get y-scale
/sx exch def % get x-scale
/tmp-matrix matrix def % create identity matrix
tmp-matrix 0 sx put
tmp-matrix 2 sy put
tmp-matrix concat
} def
Here's rotate:
/rotate {
/angle exch def
/tmp-cos angle cos def % get cosine and sine of angle
/tmp-sin angle sin def
/tmp-matrix matrix def % create identity matrix
tmp-matrix 0 tmp-cos put
tmp-matrix 1 tmp-sin put
tmp-matrix 2 tmp-sin neg put
tmp-matrix 3 tmp-cos put
tmp-matrix concat
} def
Ken (shiva@well.sf.ca.us)
Technical Details
Message-ID:
<22320@well.sf.ca.us>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!apple!well!shivaReferences:
<SBCHANIN.90Dec19115648@cocoa-krispies.ai.mit.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!apple!well!shiva From: shiva@well.sf.ca.us (Kenneth Porter) Newsgroups: comp.lang.postscript Subject: Re: What does concat do? Summary: An Introduction to Matrices Message-ID: <22320@well.sf.ca.us> Date: 25 Dec 90 00:18:32 GMT References: <SBCHANIN.90Dec19115648@cocoa-krispies.ai.mit.edu> Lines: 72