1. identmatrix

Replaces array contents with identity matrix values.

1.1. Syntax

matrix identmatrix → matrix

1.2. Stack Effects

Table 1. Before
Level Object

0

matrix (array)

Table 2. After
Level Object

0

matrix (modified array)

1.3. Description

identmatrix replaces the value of matrix with the identity matrix [1.0 0.0 0.0 1.0 0.0 0.0] and pushes the modified matrix back on the operand stack.

The identity matrix transforms any coordinate to itself without change.

The matrix operand must be an array with at least 6 elements. Only the first 6 elements are modified.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Initializing a matrix
6 array identmatrix  % → [1.0 0.0 0.0 1.0 0.0 0.0]
Resetting an existing matrix
/m [2 0 0 2 100 100] def
m identmatrix        % → [1.0 0.0 0.0 1.0 0.0 0.0]
% m is now the identity matrix
Equivalent to matrix
% These produce the same result:
matrix
6 array identmatrix

1.6. Common Use Cases

1.6.1. Reusing Matrix Arrays

% Create reusable matrix
/workMatrix 6 array def

% Reset to identity before use
workMatrix identmatrix
100 100 translate
% Use transformed matrix

% Reset again
workMatrix identmatrix
45 rotate
% Use newly transformed matrix

1.6.2. Matrix Initialization

% Initialize multiple matrices
/matrices [
  6 array identmatrix
  6 array identmatrix
  6 array identmatrix
] def

1.7. Common Pitfalls

Array Size - The array must have at least 6 elements.
4 array identmatrix  % Error: rangecheck
6 array identmatrix  % OK
8 array identmatrix  % OK (only first 6 modified)
Modifies Existing Array - Unlike matrix, identmatrix modifies an existing array.
matrix               % Creates new array
6 array identmatrix  % Uses existing array
Use with Preallocated Arrays - identmatrix is useful when you want to reuse arrays:
% Inefficient - creates many arrays:
{
  matrix currentmatrix
  % use matrix
} repeat

% Efficient - reuses one array:
/m 6 array def
{
  m identmatrix currentmatrix
  % use matrix
} repeat

1.8. Error Conditions

Error Condition

[rangecheck]

Array has fewer than 6 elements

[stackunderflow]

No operand on stack

[typecheck]

Operand is not an array

1.9. Implementation Notes

  • Only the first 6 elements are modified

  • Elements beyond index 5 are unchanged

  • The array itself is not replaced, only its contents

  • All 6 values are set to real numbers

1.10. Identity Matrix

The identity matrix has these special properties:

[1 0 0 1 0 0]

x' = 1×x + 0×y + 0 = x
y' = 0×x + 1×y + 0 = y

Properties:

  • Preserves all coordinates

  • Is its own inverse: I⁻¹ = I

  • Is the multiplicative identity: I × M = M × I = M for any matrix M

  • Has determinant = 1

1.11. See Also


Back to top

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