在横截面轮廓内创建2D网格或网格

问题描述 投票:-1回答:1

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)
r intersection mesh profile
1个回答
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 grid coord沿着该部分

create an interpolation fucntion

f_z=approxfun(Y,Z) 
Zm = f_z(Ym)             #interpolated z coordinates of the section perimeter

plot(Ym, Zm,type="b")

the depth for which we have the observed surf. velocity or Q discharge

Depth_study = 6.05

create different depths from the section bed to the study depth

Depthm = seq(Z_bed,Depth_study,zgrid/100) # different water depths w/r to 0,0 point

now for different depth, take out the indices which Zm<=Depthm

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]]))
}

since the answer comes in form of a list, we take them out by unlist func.

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=".")
© www.soinside.com 2019 - 2024. All rights reserved.