## Postscript and Geometry

### What is Postscript?

 A programming language whose instructions, when read by a Postscript interpreter, produce graphical output. Typically, Postscript programs are written by other programs like Adobe Illustrator or dvips. These are never meant to be read by humans. This talk, however, is about Postscript programs written by humans. Postscript has two beautiful features: (1) everything (well, almost) is drawn to within the accuracy of the output device and (2) everything is easily scaled.

### Basic operations

Computations are performed on a "stack"

 ` 3 4 -1.5 add mul` ` 4 -1.5 add mul` ` -1.5 add mul` ` add mul` ` mul`

### Drawing lines

 ``` 100 100 moveto 450 600 lineto stroke ```

### Drawing circles

 ``` 300 300 100 0 360 arc stroke ```

### Filling circles

 ``` 300 300 100 0 360 arc gsave 0.8 setgray fill grestore 10 setlinewidth stroke ```

### Drawing Bezier curves

 ``` 200 200 moveto 100 500 500 300 400 550 curveto stroke ```

### Displaying text

 ``` 100 100 moveto (g) show ```

### The coordinate transformation

#### The initial coordinate transformation

User space Device space

### Translations

 `200 300 translate` User space Device space

### Rotations

 ```200 300 translate 45 rotate ``` User space Device space

### Scaling

 ```200 300 translate 0.8 3 scale``` User space Device space

### Homogeneous coordinates

 Everything produced is passed through an affine coordinate transformation from user space into device space. This transformation has the form or in the language of linear transformations
 This is typically expressed in homogeneous coordinates In this formalism,

### General transformations

 ```200 300 translate [1 0 0.5 1 0 0] concat``` User space Device space

### General transformations

 ```200 300 translate [0 1 1 0 0 0] concat``` User space Device space

### What do you mean everything?

 Well, everything: lines, curves and text are all described in user space, then transformed into device space before rendered. To understand how this works, let's take a look under the hood.

### What can Postscript do?

 Apparently, not much: ultimately everything in Postscript is described in terms of lines and Bezier curves--even circular arcs:

### and text

 There is, however, a great benefit to be gained.

### How does Postscript render graphical information?

 Postscript draws a line between two points
 recursively by drawing the lines between the endpoints and midpoint
 and again and again
 until finally

### Bezier curves

 The four points define the curve where
 These can be built recursively as well.
 The curve splits into two other Bezier curves whose control points are easily obtained.
 Just keep dividing the smaller pieces
 until

### So what?

 This means that to transform a line or a curve, all we need to do is transform the control points. That's easy.

### But why would you want to write your own code?

The Economics of Computing
 After making a few widgets, the marginal cost of making more widgets is almost zero.

 Postscript is a full fledged programming language with loops and other good things.
To build this:

 1. Draw big triangle 2. Scale by 1/2 and draw smaller triangle 3. If not at the lowest level, repeat three times: Save the coordinate transformation Translate by 0 -s Draw next triangle Go to step 2 Restore coordinate transformation Rotate by 120

### From geometry

 The Elements, Book I, Proposition 1
 The Nine Point Circle

### More homogeneous coordinates

 and then
 Let's see: we need so we'll take We can accomplish this by

### Resources

 Adobe, creators of Postscript Ghostscript, a free Postscript interpreter and viewer Guide to Postscript Programming Bill Casselman's Geometry and Postscript, a text book used to teach PostScript within a Geometry course. Bill Casselman's Mathematical Graphics resources page. Peter Kleiweg's Postscript page P.S. All figures have been drawn in Postscript.