File Exchange

## INTERPNS

version 1.0.0.0 (2.74 KB) by
N-dimensional simplicial interpolation

3 Downloads

Updated 31 Mar 2011

View License

Interpolation using interpn (or inter2, interp3, etc.) offers several options - linear, nearest, spline. However an interpolation method not offered is that based on a simplicial dissection of the n-d hypercube. Since a few people have asked me for it, here it is. The dissection of the cube used breaks each hyper-rectangle in the lattice into factorial(n) simplexes.

Why might one use this tool? The "linear" interpolation method used by interpn is actually a tensor product linear interpolant. In fact, that is not truly a linear interpolant. It has some properties that can be problematic. (Look at what that interpolant does along a diagonal of the lattice. That "linear" interpolant will often interesting behavior for something one expects to be linear.)

Interpns uses a simplicial interpolation scheme, breaking each hyper-rectangle of the lattice up into a set of factorial(n) simplexes. Within any simplex, the interpolation will always be purely linear. In addition, the interpolation along a choice diagonal of that lattice will always be truly linear. This is important for those who work in color manipulations for example, using n-d lookup tables.

Finally, the simplicial interpolant, based on barycentric coordinates within any given simplex, is assured never to create ringing behavior, as might be caused by a spline for example. And simplicial interpolation will be fairly efficient.

### Cite As

John D'Errico (2021). INTERPNS (https://www.mathworks.com/matlabcentral/fileexchange/30932-interpns), MATLAB Central File Exchange. Retrieved .

### Comments and Ratings (3)

Sterling Baird

This is nice to see. Do you have any recommendations on doing interpolation on a hypersphere? Also, on a patch of the hypersphere surface with the convex hull defined by the user (in my case, a fundamental zone where equivalent symmetries in grain boundaries are ignored)? I've found and read through many references on generalized barycentric coordinates for curved shapes (e.g. spheres) in various dimensions including mean value, Wachspress, etc. coordinates, but have struggled to find code that does interpolation on a hypersphere.

John Chen

John Chen

The code works very well. The max error of the example is less than 2%.

[x1,x2] = meshgrid(0:.2:1);
z = exp(x1+x2);
Xi = rand(1000,2);
Zi = interpns(z,Xi,{0:.2:1, 0:.2:1}); %interpolate results
surf(0:.2:1,0:.2:1,z)
hold on
plot3(Xi(:,1),Xi(:,2),Zi,'r.')
Wi = sum(Xi,2);
ZZi = exp(Wi); %Exactly results
Q = (Zi - ZZi)./Zi;
max(Q) % max. error

##### MATLAB Release Compatibility
Created with R2010b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!