math::interpolation
math::interpolation
Section titled “math::interpolation”The interpolation module provides bilinear and trilinear interpolation on
flat 1D-stored grids. Query points are passed as an Nx2 or Nx3
Mat<number>; the result is a flat Array<number> with one interpolated
value per query point.
Import
Section titled “Import”use std::math::interpolationFunctions
Section titled “Functions”interpolation::bilinear(grid, shape, lo, hi, points) -> Array<number>
Section titled “interpolation::bilinear(grid, shape, lo, hi, points) -> Array<number>”Bilinear interpolation on a flat 2D grid stored in [y][x] order.
| Parameter | Type | Description |
|---|---|---|
grid | Array<number> | Flat grid values, length ny * nx |
shape | Array<int> | [ny, nx] |
lo | Array<number> | Lower bounds [y_lo, x_lo] |
hi | Array<number> | Upper bounds [y_hi, x_hi] |
points | Mat<number> | Nx2 matrix of query points [x, y] |
interpolation::trilinear(grid, shape, lo, hi, points) -> Array<number>
Section titled “interpolation::trilinear(grid, shape, lo, hi, points) -> Array<number>”Trilinear interpolation on a flat 3D grid stored in [z][y][x] order.
| Parameter | Type | Description |
|---|---|---|
grid | Array<number> | Flat grid values, length nz * ny * nx |
shape | Array<int> | [nz, ny, nx] |
lo | Array<number> | Lower bounds [z_lo, y_lo, x_lo] |
hi | Array<number> | Upper bounds [z_hi, y_hi, x_hi] |
points | Mat<number> | Nx3 matrix of query points [x, y, z] |
use std::math::interpolation
// 2x2 grid: values at corners of unit squarelet grid = [0.0, 1.0, // y=0 row 2.0, 3.0] // y=1 rowlet pts = mat(1, 2, [0.5, 0.5]) // single query point at (0.5, 0.5)let vals = interpolation::bilinear(grid, [2, 2], [0.0, 0.0], [1.0, 1.0], pts)// vals[0] == 1.5 (interpolated center value)See Also
Section titled “See Also”- math::linalg — vector operations on
Array<number> - math::rotation — 3D rotation math used with
Mat<number> - Standard Library: Math —
math::bspline2_3d_batchfor B-spline interpolation