R中的2D网格? 我有一条河断面,其剖面以Y相对Z为基准。 并希望在河床和水深之间创建网格。三角形和矩形网格都可以。网格可以相距0.01 x 0.01 m或任何其他距离。我的目标是获取每个网格的Y和Z坐标。 预先感谢您的友好合作
个人资料数据
Y=c(-30,-2,0,8,20,31)
Z=c(30,10,2,9,30,39)
答案 0 :(得分:0)
Y=c(-30,-2,0,8,20,31)
Z=c(30,10,2,9,30,39)
-在横截面内创建点网格 -选择y和z网格间距
ygrid= 50 #cm
zgrid= 20 #cm
Ym = seq(min(Y),max(Y),ygrid/100
#y沿该部分的网格坐标
f_z=approxfun(Y,Z)
Zm = f_z(Ym) #interpolated z coordinates of the section perimeter
plot(Ym, Zm,type="b")
Depth_study = 6.05
Depthm = seq(Z_bed,Depth_study,zgrid/100) # different water depths w/r to 0,0 point
list_points_mesh<-vector(("list"),length =length(Depthm))
Y_mesh<-vector(("list"),length =length(Depthm))
Z_mesh<-vector(("list"),length =length(Depthm))
for (j in 1:length(Depthm)) {
list_points_mesh[[j]] = which(Zm<=Depthm[j]) #gives indice of all the points which are below Depthm elevation
Y_mesh[[j]] = Ym[list_points_mesh[[j]]] #now we create pair of points using the indices
Z_mesh[[j]]= rep(Depthm[j],length(list_points_mesh[[j]]))
}
ym=unlist(Y_mesh) #y coord of the grid points
zm=unlist(Z_mesh) #z // // // //
mesh_coord <- data.frame(ym,zm) #list of points inside the section
points(ym,zm,pch=".")