# set up a grid
library(oce)
n <- 5
x <- seq(0, 1, length.out = n)
y <- seq(0, 1, length.out = n)
z <- seq(0, 1, length.out = n)
f <- array(1:n^3, dim = c(length(x), length(y), length(z)))
# interpolate along a diagonal line
m <- 100
xout <- seq(0, 1, length.out = m)
yout <- seq(0, 1, length.out = m)
zout <- seq(0, 1, length.out = m)
approx <- approx3d(x, y, z, f, xout, yout, zout)
# graph the results
plot(xout, approx, type = "l")
points(xout[1], f[1, 1, 1])
points(xout[m], f[n, n, n])
Run the code above in your browser using DataLab