Skip to content
Prev 922 / 29559 Next

Interpolating along an XY path]

Rob Schick wrote:
If you treat the x's and y's separately with approx you can get what you 
want (although I'm sure some careful thought would produce a better use 
of approx):

x <- c(1,3,5,5,5,4,2,1.5)
y <- c(1,1,1,2,3,3,3,3)
xypair <- cbind(x,y)
xypair
rownames(xypair) <- 1:length(x)
plot(x,y,type='l')
points(xypair)
text(x,y,rownames(xypair),offset=.5,pos=2)
points(approx(xypair[,1],n=30)$y, approx(xypair[,2],n=30)$y,col=3,pch="*")

BTW, I have a package for animal track data that contains a function 
called equalTime - it interpolates points in space (euclidean) based on 
an (approximation to an) equal time interval to create regular spaced 
points in time, assuming straight motion between fixes. You might find 
it useful. It's never really been finished, but I use it especially for 
the S4 validation of trajectory with "trip", and for quick speed 
filtering and time spent gridding.

http://staff.acecrc.org.au/~mdsumner/Rutas/

HTH, Mike.