I have a matrix describing a 2D surface and I need to be able to calculate values along the surface for an arbitrary line.
This is best explained by an example
#x and y axes
# 2D Matrix function defined as 0 except for a middle box filled with 1
# define two points
# plot contour graph of M, add points (x1,y1) and (x2,y2)
# and a line connecting the two
It actually pretty easy using the capacity of the "[" function to accept a two column matrix (and here assuming
N <- 20):
M[ cbind(xvec,yvec) ]  1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Because indices are truncated, the values won't necessary be those of the nearest points when the arguments are not integers.