计算不同高度的横截面面积 [英] Calculate area of cross section for varying height
本文介绍了计算不同高度的横截面面积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图弄清楚如何计算河流横截面的面积.
I'm trying to figure out how to calculate the area of a river cross section.
对于横截面,我在5 m宽的河流上每25厘米处有一个深度.
For the cross section I have the depth at every 25 cm over the 5 m wide river.
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)
如果有人对如何在r中完成此操作有任何建议,将非常感激.
If anyone have some suggestions of how this could be done in r it's highly appreciated.
推荐答案
我们可以使用sf
包创建一个显示横截面的多边形,然后计算面积.请注意,要创建多边形,在创建矩阵m
时,有必要再提供三个点,分别为c(0, 0)
,c(500, 0)
和c(0, 0)
.
We can use the sf
package to create a polygon showing the cross-section and then calculate the area. Notice that to create a polygon, it is necessary to provide three more points as c(0, 0)
, c(500, 0)
, and c(0, 0)
when creating the matrix m
.
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))
# View the polygon
plot(poly)
# Calcualte the area
st_area(poly)
31312.5
这篇关于计算不同高度的横截面面积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文