问题描述
我想知道在 R 中的相关随机游走中合并地形有哪些可能性。我有研究区域的数字高程模型 (DEM)。我希望我的随机步行避开陡坡区域。
walk <- function(x0,y0,head0,n,parameterMu,parameterRho,parameterMean,parameterSd)
{
# Get nr of individuals,call it k
k = length(x0)
# Create list to hold data
all.paths <- list()
for (j in 1:k)
{
# Create structure to hold data
steps <- data.frame(matrix(0,6))
colnames(steps) <- c("id","x","y","steplength","heading","turningangle")
# Insert the id,starting location and heading
steps[,"id"] = j
steps[1,"x"] = x0[j]
steps[1,"y"] = y0[j]
steps[1,"heading"] = head0[j]
# Simulate steps
for(i in 2:n)
{
# Draw step length and turning angle,compute heading
steplength = rnorm(n = 1,mean = parameterMean,sd = parameterSd)
turningangle = as.numeric(rwrappedcauchy(n = 1,mu = parameterMu,rho = parameterRho))
newbearing = as.numeric(circular(steps[i-1,"heading"]) + circular(turningangle)) %% (2*pi)
# Get new location
next.xy <- movement(x0=steps[i-1,"x"],y0=steps[i-1,"y"],step=steplength,heading=newbearing)
# Store output (xy on row i,steplength/heading on row i-1)
steps[i,"x"] <- next.xy[1,"x"]
steps[i,"y"] <- next.xy[1,"y"]
steps[i,"steplength"] <- next.xy[1,"step"]
steps[i,"heading"] <- newbearing
steps[i,"turningangle"] <- turningangle
# Store trajectory in list
all.paths[[j]] <- steps
}
# Return output
return(all.paths)
}
运动功能:
movement <- function(x0,step,heading)
{
x_new <- x0 + sin(heading)*step
y_new <- y0 + cos(heading)*step
move.temp <- data.frame(x = x_new,y = y_new,step = step,head = heading)
return(move.temp)
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)