Mathematics in action: affine transformations and PostScript

Here’s the next in the mathematics in action series.

An important group of geometric transformations are the affine transformations, such as translations, reflections, and rotations. They are defined by a combination of a matrix multiplication and a translation:

Such transformations are an important part of the PostScript page description language. For example, the PostScript code below, after the initial header, specifies a black letter F, and another in blue, translated by (50, 50):

%!PS-Adobe-3.0
%%BoundingBox: 0 0 196 118
%%Pages: 0
%%DocumentFonts: Times-Roman
%%DocumentNeededFonts: Times-Roman
%%Orientation: Portrait
%%EndComments
%%EndProlog
gsave newpath 100 dict begin /Times-Roman findfont 50 scalefont setfont

gsave 0 setgray 0 0 moveto (F) show grestore

gsave 0 0 1 setrgbcolor 50 50 translate 0 0 moveto (F) show grestore

The output is included in this picture:

But of course that is using only the (ef) part of the transformation. More interesting is a rotation through an angle θ, where the matrix is:

PostScript allows this to be specified using a translation and a rotation angle in degrees (red F) or as an (abcdef) matrix which combines the rotation matrix with a (180, 0) translation (grey F):

gsave 1 0 0 setrgbcolor 100 0 translate 30 rotate 0 0 moveto (F) show grestore

gsave 0.5 setgray 30 [0.8660 0.5 -0.5 0.8660 180 0] concat 0 0 moveto (F) show grestore

A diagonal matrix provides scaling in the x and y directions, with negative scaling factors giving a reflection. Again, PostScript allows the scaling factors to be provided directly (green F), or as an (abcdef) matrix (brown F):

gsave 0 0.7 0 setrgbcolor 100 100 translate -2 0.5 scale 0 0 moveto (F) show grestore

gsave 0.5 0.3 0 setrgbcolor [-2 0 0 0.5 175 75] concat 0 0 moveto (F) show grestore

end grestore showpage
%%Trailer
%%EOF

Copying and pasting the three blocks of PostScript into a text file with a .EPS extension will give the coloured image above, which can be viewed by printing it, or by inserting it into a Microsoft Word document. Experimentation with other, more complex, affine transformations is easy that way.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s