Skip to main content

matrix: Matrix Visualization Function

Structured Numerical Data Display with Spatial Organization

The matrix function renders matrix data structures as organized numerical grids. This enables visual debugging of transformation matrices and mathematical computations with precise spatial layout.

Mathematical Visualization

Matrix elements are displayed using digit-based rendering: Matrixn×nVisual GridspatialMatrix_{n \times n} \rightarrow \text{Visual Grid}_{spatial} where each element mijm_{ij} is rendered at position (iscale,jscale)(i \cdot scale, j \cdot scale) with numerical precision.

Function Variants

FunctionMatrix TypeGrid SizeSpatial Bounds
matrixMat2(st, M)2×2 matrix2×22 \times 22offset2 \cdot\|offset\|
matrixMat3(st, M)3×3 matrix3×33 \times 33offset3 \cdot\|offset\|
matrixMat4(st, M)4×4 matrix4×44 \times 44offset4 \cdot\|offset\|

Display Configuration

Rendering parameters control layout precision:

  • DIGITS_SIZE: Element scaling factor (default: 0.02)
  • DIGITS_VALUE_OFFSET: Grid positioning offset (default: (-6.0, 3.0))
  • Background alpha: Semi-transparent overlay (0.5 opacity)

Spatial Bounds Calculation

Display area is computed as: bounds=DIGITS_SIZE×DIGITS_VALUE_OFFSET×dimensionbounds = DIGITS\_SIZE \times |DIGITS\_VALUE\_OFFSET| \times dimension

Live Editor
const fragment = () => {
      const scale = iTime.sin().mul(0.5).add(1.5)
      const M = mat2(scale, 0, 0, scale)
      const overlay = matrix(uv.mul(0.3), M)
      return vec4(uv.x, uv.y, 0.5, 1).add(overlay)
}