计算横截面积作为高度的函数

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

我正在试图弄清楚如何计算不同水位的河流横截面的充水面积。

对于横截面,我在5米宽的河流上每25厘米有一个深度,该区域可以根据一个很好回答的前一个问题来计算Calculate area of cross section for varying height

x_profile <- seq(0, 500, 25)
y_profile <- c(50, 73, 64, 59, 60, 64, 82, 78, 79, 76, 72, 
           68, 63, 65, 62, 61, 56, 50, 44, 39, 25)

library(sf)

#Create matrix with coordinates
m <- matrix(c(0, x_profile, 500, 0, 0, -y_profile, 0, 0),
        byrow = FALSE, ncol = 2)

#Create a polygon
poly <- st_polygon(list(m))

# Calcualte the area
st_area(poly)

但是这个横截面只是部分地充满了水,而我现在试图计算出充满水的横截面。

水开始从最深部分填充横截面,然后深度变化,例如:

water_level<-c(40, 38, 25, 33, 40, 42, 50, 39)

有没有人对如何在r中做到这一点有任何想法?提前致谢。

r area integral
1个回答
5
投票

此函数计算轮廓与轮廓底部指定深度处的直线的交点。它有点多余,因为它还需要x和y轮廓值,理论上可以从profile中提取:

filler <- function(depth, profile, xprof, yprof, xdelta=100, ydelta=100){
    d = -(max(yprof))+depth
    xr = range(xprof)
    yr = range(-yprof)
    xdelta = 100
    xc = xr[c(1,2,2,1,1)] + c(-xdelta, xdelta, xdelta, -xdelta, -xdelta)
    yc = c(d, d, min(yr)-ydelta, min(yr)-ydelta, d)
    water = st_polygon(list(cbind(xc,yc)))
    st_intersection(profile, water)
}

所以在使用中:

> plot(poly)
> plot(filler(40, poly, x_profile, y_profile), add=TRUE, col="green")
> plot(filler(30, poly, x_profile, y_profile), add=TRUE, col="red")
> plot(filler(15, poly, x_profile, y_profile), add=TRUE, col="blue")

depths

请注意,第一个绿色区域略微被较深的区域覆盖。另请注意蓝色区域如何分为两部分。您可以使用st_area获得横截面,并且在深度为零时,该区域为零:

 > st_area(filler(20, poly, x_profile, y_profile))
[1] 2450.761
> st_area(filler(2, poly, x_profile, y_profile))
[1] 15.27778
> st_area(filler(0, poly, x_profile, y_profile))
[1] 0

不确定如果你超越个人资料的顶部会发生什么......

© www.soinside.com 2019 - 2024. All rights reserved.