1. translate

Moves the origin of the user coordinate system.

1.1. Syntax

tx ty translate → -
tx ty matrix translate → matrix

1.2. Stack Effects

Table 1. Before
Level Object

1

ty (number)

0

tx (number)

Table 2. After (first form)
Level Object

(empty)

No results

Table 3. After (second form)
Level Object

0

matrix (modified matrix)

1.3. Description

With no matrix operand, translate builds a temporary transformation matrix T and concatenates it with the current transformation matrix (CTM). Precisely, translate replaces the CTM by T × CTM.

The effect is to move the origin of the user coordinate system by tx units in the x direction and ty units in the y direction relative to the former user coordinate system. The sizes of the x and y units and the orientation of the axes are unchanged.

If the matrix operand is supplied, translate replaces the value of matrix by T and pushes the modified matrix back on the operand stack. In this case, translate does not affect the CTM.

The translation matrix T has the form:

[1 0 0 1 tx ty]

This transforms coordinates according to:

x' = x + tx
y' = y + ty

1.4. PostScript Level

Level 1 and later

1.5. Examples

Simple translation
100 200 translate  % Move origin to (100, 200)
0 0 moveto         % Now at (100, 200) in original coordinates
50 50 lineto       % Line to (150, 250) in original coordinates
stroke
Centering content
% Center a 200x100 rectangle on letter page (612x792)
306 396 translate  % Move to center
-100 -50 translate % Offset by half size
0 0 moveto
200 0 lineto
200 100 lineto
0 100 lineto
closepath
stroke
Multiple translations
50 50 translate    % Origin now at (50, 50)
100 100 translate  % Origin now at (150, 150)
% Translations accumulate

1.6. Common Use Cases

1.6.1. Positioning Graphics

/drawBox {
  % Draw a 100x100 box at current origin
  newpath
  0 0 moveto
  100 0 lineto
  100 100 lineto
  0 100 lineto
  closepath
  stroke
} def

100 100 translate
drawBox           % Box at (100, 100)

150 0 translate
drawBox           % Box at (250, 100)

1.6.2. Page Layout

% Set up margins
72 72 translate   % 1 inch margins on letter page
% Content is now inset from page edges

1.6.3. Building Transformation Matrices

% Create translation matrix without affecting CTM
matrix              % Get identity matrix
50 100 translate   % Modify to translation matrix
% Stack now has [1 0 0 1 50 100]

1.7. Common Pitfalls

Coordinate System, Not Content - translate moves the coordinate system, not the content. Drawing at (0, 0) after translation draws at the new origin location.
100 100 moveto
50 50 lineto
stroke

100 100 translate  % Moves coordinate system
100 100 moveto     % Actually at (200, 200) in original space
150 150 lineto     % Actually at (250, 250) in original space
stroke
Transformations Accumulate - Multiple translations add together. Use gsave/grestore to isolate transformations.
50 50 translate
100 100 translate  % Origin is now at (150, 150), not (100, 100)

% Better approach:
gsave
  100 100 translate
  % Draw content
grestore
% Original coordinate system restored
Readable Layout Code - Use translate to establish drawing origins, making code more readable:
% Clear intent: position then draw
200 300 translate
/drawLogo load exec

% Less clear: pass coordinates everywhere
200 300 /drawLogo load exec

1.8. Error Conditions

Error Condition

[rangecheck]

Resulting matrix values exceed implementation limits

[stackunderflow]

Fewer than 2 operands on stack (first form) or fewer than 3 (second form)

[typecheck]

Operands are not numbers, or matrix operand is not an array

1.9. Implementation Notes

  • Translation is one of the fastest transformations

  • The CTM is stored in device space, so very large translation values may lose precision

  • Translations do not affect line width, dash patterns, or other graphics state parameters

  • The transformation matrix is applied during path construction, not during painting

1.10. Matrix Mathematics

The translation matrix for translate by (tx, ty) is:

T = [1  0  0  1  tx  ty]

Concatenating with the CTM:

CTM' = T × CTM
     = [1  0  0  1  tx  ty] × [a  b  c  d  e  f]
     = [a  b  c  d  (a×tx + c×ty + e)  (b×tx + d×ty + f)]

1.11. Performance Considerations

  • Very lightweight operation

  • No path flattening or other expensive operations

  • Can be used frequently without performance concerns

  • Matrix operations are optimized in most implementations

1.12. Transformation Order

Transformations are applied in reverse order of specification:

translate1 translate2 translate3
% Applied as: translate3(translate2(translate1(point)))

This is because each transformation modifies the CTM by left-multiplication.

1.13. See Also


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.