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)
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 grid coord沿着该部分
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=".")