I am attempting to smooth the jagged paths of animal tracks to determine their 
distances with greater accuracy. The data is in the form of (x,y) 2D 
coordinates. My end goal is to produce a set of interpolating points whereby 
their Cartesian distances are equal to each other. So far, I have been able to 
produce a path with a specified number of interpolating points via spline(). 
However, these points are not equidistant.

An example data set and my code thus far:

df <- structure(list(x = c(329L, 329L, 329L, 329L, 330L, 330L, 330L, 
330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 
330L, 330L, 330L, 330L, 331L, 331L, 331L, 332L, 332L, 333L, 333L, 
333L, 333L, 333L, 333L, 333L, 333L, 333L, 333L, 333L, 334L, 334L, 
334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 
334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 
334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 
334L, 334L, 334L, 334L, 334L, 334L, 334L, 333L, 333L, 332L, 332L, 
332L, 332L, 332L, 332L, 333L, 333L, 333L, 332L, 333L, 331L, 331L, 
330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 329L, 329L, 329L, 
329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 
329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 328L, 
327L, 327L, 327L, 327L, 327L, 326L, 326L, 325L, 325L, 325L, 325L, 
325L, 323L, 322L, 321L, 320L, 319L, 319L, 319L, 319L, 319L, 319L
), y = c(255L, 256L, 256L, 256L, 257L, 257L, 257L, 257L, 257L, 
257L, 257L, 257L, 257L, 257L, 258L, 259L, 259L, 259L, 261L, 261L, 
262L, 263L, 263L, 264L, 265L, 266L, 266L, 267L, 268L, 269L, 270L, 
272L, 272L, 273L, 274L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 
275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 
276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 
276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 
276L, 276L, 276L, 276L, 277L, 278L, 278L, 279L, 280L, 281L, 283L, 
284L, 285L, 287L, 288L, 290L, 291L, 291L, 294L, 295L, 297L, 298L, 
299L, 300L, 301L, 302L, 302L, 304L, 305L, 306L, 306L, 308L, 308L, 
308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 
308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 309L, 
310L, 311L, 311L, 312L, 313L, 314L, 315L, 318L, 319L, 320L, 322L, 
323L, 324L, 325L, 325L, 325L, 325L, 326L, 326L, 327L)), .Names = c("x", 
"y"), row.names = c(NA, -150L), class = "data.frame")

require(Momocs)

cumdist <- coo_perimcum(df)
sx <- spline(cumdist, df[, 1], method = "natural", n = 10)
sy <- spline(cumdist, df[, 2], method = "natural", n = 10)
splines <- cbind.data.frame(x = sx$y, y = sy$y)

par(pty = "s")
with(df, plot(x, y, main = "Example Locomotor Path - Cubic Spline Smoothing",
              axes = FALSE, frame.plot = TRUE, type = "l", col = "light gray", 
lwd = 3))
with(splines, lines(x, y, type = "b", col = "red", lwd = 3))

Thank you!

Salvatore A. Sidoti
PhD Student
Behavioral Ecology

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to