Skip to main content
added 12 characters in body
Source Link
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.

 

EDIT: 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"))

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.

EDIT: 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"))

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"))
deleted 244 characters in body
Source Link
jsta
  • 1.4k
  • 1
  • 15
  • 32

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.

EDIT: 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,2060,3),(seq(1,2060,3))+ceiling(abs(rnorm(760)*10*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
#function from http://benn.org/2007/01/06/rotating-coordinates-around-a-centre/
rotatenpath.p<rot<-function elide(X1,Y1npathSL,Pxrotate=sample(seq(0,Py360,D10.01){##X1=Xcoords, Y1=Ycoords, Px=Rotation pt X, Py = Rotation pt Y, D1=clockwise degrees rotation
  d1=-D1*pi/180
  xRot=Px+cos(d1)*(X1-Px)-sin(d1) * (Y1-Py)
  yRot=Py+sin(d1)*(X1-Px1) + cos,center=apply(d1) * bbox(Y1-PynpathSL)
  rot=cbind(xRot, yRot1,mean)
  rot
}
)
npath.matrot.rot<mat<-rotate.pcoordinates(npath.mat[,1],npath.mat[,2],npath.mat[1,1],npath.mat[1,2],sample(seq(0,360,0.01),1)rot)[[1]][[1]]
npath.rot<-Lines(list(Line(npath.mat.rot.mat)),ID="npr") 


npath.alllines<-SpatialLines(list(path,npath,npath.rot))
plot(npath.alllines,col=c("black","red","green"))

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.

library(sp)

#create the nodes of a spatiallines object
set.seed(2)
path.mat<-matrix(c(seq(1,20,3),(seq(1,20,3))+ceiling(abs(rnorm(7)*10))),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")


#randomly rotate between 0 and 360 degrees
#function from http://benn.org/2007/01/06/rotating-coordinates-around-a-centre/
rotate.p<-function (X1,Y1,Px,Py,D1){##X1=Xcoords, Y1=Ycoords, Px=Rotation pt X, Py = Rotation pt Y, D1=clockwise degrees rotation
  d1=-D1*pi/180
  xRot=Px+cos(d1)*(X1-Px)-sin(d1) * (Y1-Py)
  yRot=Py+sin(d1)*(X1-Px) + cos(d1) * (Y1-Py)
  rot=cbind(xRot, yRot)
  rot
}

npath.mat.rot<-rotate.p(npath.mat[,1],npath.mat[,2],npath.mat[1,1],npath.mat[1,2],sample(seq(0,360,0.01),1))
npath.rot<-Lines(list(Line(npath.mat.rot)),ID="npr")

npath.alllines<-SpatialLines(list(path,npath,npath.rot))
plot(npath.alllines,col=c("black","red","green"))

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.

EDIT: 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"))
Source Link
jsta
  • 1.4k
  • 1
  • 15
  • 32

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.

library(sp)

#create the nodes of a spatiallines object
set.seed(2)
path.mat<-matrix(c(seq(1,20,3),(seq(1,20,3))+ceiling(abs(rnorm(7)*10))),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")


#randomly rotate between 0 and 360 degrees
#function from http://benn.org/2007/01/06/rotating-coordinates-around-a-centre/
rotate.p<-function (X1,Y1,Px,Py,D1){##X1=Xcoords, Y1=Ycoords, Px=Rotation pt X, Py = Rotation pt Y, D1=clockwise degrees rotation
  d1=-D1*pi/180
  xRot=Px+cos(d1)*(X1-Px)-sin(d1) * (Y1-Py)
  yRot=Py+sin(d1)*(X1-Px) + cos(d1) * (Y1-Py)
  rot=cbind(xRot, yRot)
  rot
}

npath.mat.rot<-rotate.p(npath.mat[,1],npath.mat[,2],npath.mat[1,1],npath.mat[1,2],sample(seq(0,360,0.01),1))
npath.rot<-Lines(list(Line(npath.mat.rot)),ID="npr")

npath.alllines<-SpatialLines(list(path,npath,npath.rot))
plot(npath.alllines,col=c("black","red","green"))