x <- linspace(-1, 1, 11)
y <- linspace(-1, 1, 11)
mgrid <- meshgrid(x, y)
Z <- mgrid$X^2 + mgrid$Y^2
xp <- yp <- linspace(-1, 1, 101)
method <- "linear"
zp <- interp2(x, y, Z, xp, yp, method)
plot(xp, zp, type = "l", col = "blue")
method = "nearest"
zp <- interp2(x, y, Z, xp, yp, method)
lines(xp, zp, col = "red")
grid()
Run the code above in your browser using DataLab