Skip to content

Interpolating along an XY path

3 messages · Rob Schick, Barry Rowlingson, Michael Sumner

#
Rob Schick wrote:
What exactly do you mean by 'regularize'?

  Have you got (x,y,t) data for spotting an animal at point (x,y) at 
time t where t is irregular, and you want to 'regularize' in t? Or do 
you want to regularize in space, so you end up with points all the same 
distance apart? That might not be possible depending on the spacing of 
your points...

  I think you're going to end up interpolating between pairs of points. 
Its quite easy to interpolate points between (x0,y0) and (x1,y1), the 
coords are just (x0+(1:N)*dx, y0+(1:N)*dy) where dx is (x1-x0)/N and 
similarly for y. Or I might be one off there...

Barry
#
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.