Skip to main content
3 of 3
added 12 characters in body
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Here is some R code. The paper says that they randomly shifted the path. I take that to mean they randomly shifted each node of the path. They say that the path was shifted between 0 and 30 but I think that it only makes sense to shift between -30 and 30.


taking advantage of center of gravity rotation in the maptools package

library(sp)
library(maptools)

#create the nodes of a spatiallines object
set.seed(2)
path.mat<-matrix(c(seq(1,60,3),(seq(1,60,3))+ceiling(abs(rnorm(60)*5))),ncol=2)
path<-Lines(list(Line(path.mat)),ID="p")


#randomly shift nodes between 0 and 30km 
shiftx<-sample(seq(-30,30,0.01),nrow(path.mat))
shifty<-sample(seq(-30,30,0.01),nrow(path.mat))
npath.mat<-cbind(path.mat[,1]+shiftx,path.mat[,2]+shifty)
npath<-Lines(list(Line(npath.mat)),ID="np")
npathSL<-SpatialLines(list(npath))

#randomly rotate between 0 and 360 degrees
npath.rot<-elide(npathSL,rotate=sample(seq(0,360,0.01),1),center=apply(bbox(npathSL),1,mean))
npath.rot.mat<-coordinates(npath.rot)[[1]][[1]]
npath.rot<-Lines(list(Line(npath.rot.mat)),ID="npr")


npath.alllines<-SpatialLines(list(path,npath,npath.rot))
plot(npath.alllines,col=c("black","red","green"))
jsta
  • 1.4k
  • 1
  • 15
  • 32