计算横截面面积作为高度的函数 [英] Calculate area of cross-section as function of height

查看:27
本文介绍了计算横截面面积作为高度的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何计算不同水位下河流横截面的水填充面积.

对于横截面,我在 5 m 宽的河流上每 25 cm 有一个深度,该面积可以根据上一个很好回答的问题来计算

请注意,第一个绿色区域被较不深的区域略微覆盖.还要注意蓝色区域是如何分成两部分的.您可以使用 st_area 获得横截面,并且在深度为零处面积为零:

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

不确定如果您在个人资料顶部上方会发生什么...

I'm trying to figure out how to calculate the water filled area of a river cross section for different water levels.

For the cross-section I have the depth at every 25 cm over the 5 m wide river and the area can be calculated based on a nicely answered previous question 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)

But this cross section is only partially filled with water, and it is the water filled cross section that I now try to calculate.

The water starts filling the cross section from the deepest part and the depth then vary, for example like this:

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

Does anyone have any ideas on how this could be done in r? Thanks in advance.

解决方案

This function computes the intersection of the profile with a line at the specified depth from the bottom of the profile. It is slightly redundant in that it also needs the x and y profile values which could in theory be extracted from 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)
}

So in use:

> 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")

Note the first green region is slightly covered by the less deeper regions. Note also how the blue regions is in two sections. You can get the cross-section with st_area, and at depth zero the area is zero:

 > 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

Not sure what happens if you go above the top of your profile...

这篇关于计算横截面面积作为高度的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆