1. identmatrix
Replaces array contents with identity matrix values.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| Level | Object |
|---|---|
0 |
|
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.5. Examples
6 array identmatrix % → [1.0 0.0 0.0 1.0 0.0 0.0]
/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
% These produce the same result:
matrix
6 array identmatrix
1.6. Common Use Cases
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 |
|---|---|
[ |
Array has fewer than 6 elements |
[ |
No operand on stack |
[ |
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
-
matrix- Create new identity matrix array -
currentmatrix- Get current transformation -
defaultmatrix- Get device default matrix -
initmatrix- Reset CTM to identity