Examples Using Frames of Reference

5.6.1 Examples Using Frames of Reference

Sometimes you might want to think when you draw in a landscape frame rather than the usual portrait frame. The following code draws an arrow pointing up on a page when you turn it in landscape mode.

%!

0 setlinewidth
72 72 scale

% move the origin to the lower right corner
8.5 0 translate

% rotate by 90 degrees
90 rotate

% now we are in a "landscape" frame of reference; save it.
gsave

% move to the centre of the page:
5.5 4.25 translate

% draw an arrow -- first the body
newpath
.5 setlinewidth

0 -1.5 moveto
0 1.5 lineto
stroke

%then the head
0 1.5 translate

-135 rotate
0 1 moveto
0 0 lineto
1 0 lineto
stroke

grestore
showpage

Here is the output (scaled to fit this page!):

Affine transformations map conics to conics (prove this as an exercise). In particular, ellipses map to ellipses. So if we want to draw an ellipse whose major axis is 2 inches and whose minor axis is 1 inch, we draw a circle in an appropriate frame of reference:

%!

0 setlinewidth
72 72 scale
gsave

% draw in the centre of the page
4.25 5.5 translate

% rotate the world by 45 degrees
45 rotate


% now scale the x direction so it is twice that of the y direction
2 1 scale

% draw the circle
0 0 1 0 360 arc

%put us back in our saved graphics state
stroke

grestore
showpage


This creates in the centre of the page:


David Maxwell, who is still writing this, would like to hear your comments and suggestions. And remember, parts of this manual are based on P.J. Weingartner's work: A First Guide to PostScript.