Simple CTM Manipulation

Simple CTM Manipulation


 

Introduction

In this section of the course we will introduce the Current Transformation  Matrix (CTM) and how to manipulate it.

  • rotate
  • scale
  • translate

Rotating the Coordinate System

All PostScript commands conform to the CTM. the ability to easily change  the CTM allows any image to be rotated, scaled or moved, simply by  preceeding it with a CTM changing command.

moveto sets the current point.

Once set, the current point remains fixed to the paper until moved  again.

rotate changes the current coordinate system (usually called the CTM).

The current point remains with the paper, and does not move with the  coordinate system.

Program "Up Hill Text"


/Times-Bold findfont

50 scalefont

setfont

108 450 moveto

30 rotate

(Up Hill Battle) show

showpage
 


 

Program "Up Hill Text" - Details


 


/Times-Bold findfont

50 scalefont

setfont

108 450 moveto
 



/Times-Bold findfont

50 scalefont

setfont

108 450 moveto

30 rotate
 



/Times-Bold findfont

50 scalefont

setfont

108 450 moveto

30 rotate

(Up Hill Battle) show
 


 Question: What would happen if the rotate came before the move? Spinning the Axis (rotate)Solution

Rotating the coordinate system (rotate)

anglerotate-

 Positive angles rotate coordinate system counter-clockwise.

Negative angles rotate coordinate system clockwise.

rotate is cumulative.

"60 rotate" rotates coordinate system an additional 60 degrees  counter-clockwise.

The current origin is always the pivot point of the rotation.


30 rotate 60 rotate
 is the same as


90 rotate


 

Program "Down Hill"


/Times-Italic findfont

70 scalefont

setfont

150 500 moveto

(Down) show

-60 rotate

(Hill) show

showpage
 


 

Program "Down Hill" - Details




/Times-Italic findfont

70 scalefont

setfont

150 500 moveto

(Down) show
 


/Times-Italic findfont

70 scalefont

setfont

150 500 moveto

(Down) show

-60 rotate

 


/Times-Italic findfont

70 scalefont

setfont

150 500 moveto

(Down) show

-60 rotate

(Hill) show

 


 

Exercise

Try adding the word "Race" after "Hill" but parallel to the bottom edge of  the paper.

Stretching the Coordinate System (scale)

Sx Syscale-

 Changes the CTM by stretching the X-axis by Sx, and the Y-axis by Sy.

The current point remains fixed to the paper.

Text conforms to the CTM, so subsequent text will be stretched.

Stretches current axis, not original axis.


    3 14 scale
 is the same as


    3 1 scale   1 14 scale
 or


    1 7 scale   3 2 scale
 

Tall Letters


/Times-Bold findfont

60 scalefont

setfont

150 250 moveto

1 5 scale

(POSTSCRIPT) show

showpage


 

Exercise

swap the move and scale and see what happens

Program "Tall Letters" - Details



/Times-Bold findfont

60 scalefont

setfont

150 250 moveto
 


/Times-Bold findfont

60 scalefont

setfont

150 250 moveto

1 5 scale
 

Note that although the scale changes the coordinate system, the current point remains fixed on the page.


 


/Times-Bold findfont

60 scalefont

setfont

150 250 moveto

1 5 scale

(POSTSCRIPT) show
 


 Question: What would happen if the moveto came after the scale?

Short Letters


/Times-Bold findfont

30 scalefont

setfont

5 1 scale

30 250 moveto

(POSTSCRIPT) show

showpage



/Times-Bold findfont

30 scalefont

setfont

5 1 scale
 



/Times-Bold findfont

30 scalefont

setfont

5 1 scale

30 250 moveto
 



/Times-Bold findfont

30 scalefont

setfont

5 1 scale

30 250 moveto

(POSTSCRIPT) show
 


 

Moving the Coordinate System (translate)

Tx Tytranslate-

 

Moves the origin to TxTy.

The current point (if any) remains fixed to the paper.


So far we have learned three operators that affect the Current  Transformation Matrix (CTM):

  • rotate
  • scale
  • translate

All three change the CTM persistently.

All three use the most recent value of the CTM when computing the new  value.

Program "Venus & Mars" - Output


/Helvetica findfont

40 scalefont setfont

200 100 translate

0 0 moveto

(Venus) show

72 144 translate

0 0 moveto

(Mars) show

showpage


 

Program "Venus & Mars" - Details


/Helvetica findfont

40 scalefont setfont

200 100 translate
 



/Helvetica findfont

40 scalefont setfont

200 100 translate

0 0 moveto
 



/Helvetica findfont

40 scalefont setfont

200 100 translate

0 0 moveto

(Venus) show
 



/Helvetica findfont

40 scalefont setfont

200 100 translate

0 0 moveto

(Venus) show

72 144 translate
 



/Helvetica findfont

40 scalefont setfont

200 100 translate

0 0 moveto

(Venus) show

72 144 translate

0 0 moveto
 



/Helvetica findfont

40 scalefont setfont

200 100 translate

0 0 moveto

(Venus) show

72 144 translate

0 0 moveto

(Mars) show
 


 Question: What happens if the second moveto were omitted?
What about the  first?

Wrong Reading

A negative scale factor "flips" the axis; The positive and negative  directions are reversed.

The show command always conforms to the CTM, so flipping the axis will  also flip the text.

A -1 1 scale flips the X-axis.

A 1 -1 scale flips the Y-axis.

You can combine flipping and stretching at the same time, 2 -3 scale,  stretches and flips at the same time.

Program "Mirror Image Text"


 


/Times-Italic findfont

50 scalefont

setfont

432 200 translate
 



/Times-Italic findfont

50 scalefont

setfont

432 200 translate

-1 1 scale
 



/Times-Italic findfont

50 scalefont

setfont

432 200 translate

-1 1 scale

50 50 moveto
 



/Times-Italic findfont

50 scalefont

setfont

432 200 translate

-1 1 scale

50 50 moveto

(Mirror) show
 

Question:

What if the moveto was before the scale? What if negative  scales are used for both X and Y?

Review

The Current Transformation Matrix (CTM) controls the mapping from user  space to the paper.

rotate - changes the CTM by spinning the axis around the origin.

scale - changes the CTM by stretching the X and Y axis (negative  numbers stretch and flip).

translate - changes the CTM by moving the origin.

CTM changes are persistent.

All subsequent operations conform to the new CTM.

You can change the CTM as often as you like.

Rule of thumb:
translate first, then rotate, then scale.


[Home] [Goals] [Intro] [Simple Text] [Simple CTM]

Copyright © 1998, Mefco, Inc., All Rights Reserved
"PostScript" is a registered trademark of
Adobe Systems, Inc.