1. concat

Concatenates a matrix with the current transformation matrix.

1.1. Syntax

matrix concat → -

1.2. Stack Effects

Table 1. Before
Level Object

0

matrix (6-element array)

Table 2. After
Level Object

(empty)

No results

1.3. Description

concat concatenates matrix with the current transformation matrix (CTM). Precisely, concat replaces the CTM by matrix × CTM.

The effect is to define a new user space whose coordinates are transformed into the former user space according to matrix. This allows arbitrary transformations including combinations of translation, scaling, rotation, and skewing.

The matrix operand must be a 6-element array of numbers representing a transformation matrix in the form:

[a b c d tx ty]

This matrix transforms coordinates according to:

x' = a×x + c×y + tx
y' = b×x + d×y + ty

1.4. PostScript Level

Level 1 and later

1.5. Examples

Simple concatenation
% Translation matrix
[1 0 0 1 100 200] concat
% Equivalent to: 100 200 translate
Combined transformations
% Scale by 2, rotate 45 degrees
[1.414 1.414 -1.414 1.414 0 0] concat
% Approximately equivalent to: 2 2 scale 45 rotate
Shearing transformation
% Horizontal shear
[1 0 0.5 1 0 0] concat
newpath
0 0 moveto
100 0 lineto
100 100 lineto
0 100 lineto
closepath
stroke  % Draws parallelogram

1.6. Common Use Cases

1.6.1. Building Complex Transformations

% Build transformation step by step
matrix               % Start with identity
50 100 translate     % Add translation
2 2 scale           % Add scaling
45 rotate           % Add rotation
concat              % Apply to CTM

1.6.2. Applying Precomputed Matrices

% Store transformation for reuse
/myTransform [2 0 0 2 100 100] def

% Use it multiple times
gsave
  myTransform concat
  % Draw content
grestore

gsave
  myTransform concat
  % Draw more content
grestore

1.6.3. Skew/Shear Effects

% Italic effect (horizontal shear)
[1 0 0.25 1 0 0] concat
/Helvetica findfont 24 scalefont setfont
0 0 moveto
(Slanted Text) show

% Vertical shear
[1 0.25 0 1 0 0] concat

1.6.4. Mirror Transformations

% Horizontal mirror around x=100
[- 1 0 0 1 200 0] concat

% Vertical mirror around y=100
[1 0 0 -1 0 200] concat

1.7. Common Pitfalls

Matrix Format - The matrix must be exactly 6 elements in the correct order [a b c d tx ty].
% Wrong: only 4 elements
[2 0 0 2] concat    % Error!

% Wrong: wrong order
[100 200 2 0 0 2] concat  % Incorrect transformation

% Right:
[2 0 0 2 100 200] concat
Identity Matrix - Concatenating the identity matrix has no effect.
[1 0 0 1 0 0] concat  % Does nothing
Order of Operations - Matrix multiplication is not commutative. Order matters!
% These produce different results:
[2 0 0 2 0 0] concat     % Scale first
[1 0 0 1 100 100] concat % Then translate

[1 0 0 1 100 100] concat % Translate first
[2 0 0 2 0 0] concat     % Then scale
Use Helper Operators - For simple transformations, use translate, scale, and rotate instead of concat.
% Clearer:
100 200 translate
2 2 scale

% Less clear:
[2 0 0 2 100 200] concat
Build Matrices Separately - Build transformation matrices separately for clarity:
matrix                  % Start with identity
100 200 translate      % Add translation
45 rotate              % Add rotation
/myMatrix exch def     % Save result
myMatrix concat        % Apply it

1.8. Error Conditions

Error Condition

[rangecheck]

matrix does not have exactly 6 elements, or resulting matrix values exceed implementation limits

[stackunderflow]

No operand on stack

[typecheck]

Operand is not an array, or array elements are not all numbers

1.9. Implementation Notes

  • The matrix operand is not modified by concat

  • Very large or very small matrix values may cause precision loss

  • Degenerate matrices (determinant = 0) create non-invertible transformations

  • The operation is equivalent to: CTM' = matrix × CTM

1.10. Matrix Mathematics

Given a transformation matrix M:

M = [a  b  c  d  tx  ty]

And the current CTM:

CTM = [a₀  b₀  c₀  d₀  tx₀  ty₀]

concat computes:

CTM' = M × CTM
     = [a  b  c  d  tx  ty] × [a₀  b₀  c₀  d₀  tx₀  ty₀]
     = [a×a₀+b×c₀         a×b₀+b×d₀
        c×a₀+d×c₀         c×b₀+d×d₀
        tx×a₀+ty×c₀+tx₀   tx×b₀+ty×d₀+ty₀]

1.11. Transformation Components

A general transformation matrix can represent:

Component Matrix Elements

Scaling

a controls x-scaling, d controls y-scaling

Rotation

When a=d=cos(θ) and b=-c=sin(θ)

Shearing

b causes x-shear, c causes y-shear

Translation

tx and ty control offset

Reflection

Negative a flips horizontally, negative d flips vertically

1.12. Decomposition Example

% Complex transformation
/complexMatrix [1.414 1.414 -1.414 1.414 100 200] def

% This is approximately equivalent to:
100 200 translate  % Translation (tx=100, ty=200)
45 rotate          % Rotation (θ=45°)
2 2 scale          % Scaling (sx=sy=√2≈1.414)

1.13. Performance Considerations

  • concat is a lightweight operation

  • No path recomputation is required

  • Matrix multiplication is optimized

  • Using concat with precomputed matrices can be faster than multiple individual transformations

1.14. Relationship to Other Operators

% These are equivalent:

% Using individual operators:
100 200 translate
2 2 scale
45 rotate

% Using concat:
matrix
100 200 translate
2 2 scale
45 rotate
concat

% Direct concat (requires computed matrix):
[1.414 1.414 -2.828 1.414 100 200] concat

1.15. Building Transformation Matrices

% Create a reusable transformation
/buildTransform {
  % angle sx sy tx ty buildTransform -> matrix
  matrix
  5 -1 roll translate  % Apply translation
  4 1 roll scale       % Apply scaling
  rotate               % Apply rotation
} def

% Use it:
45 2 3 100 200 buildTransform concat

1.16. See Also


Back to top

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