【问题标题】:Calculating All Intersected Area of Irregular Shape that have been given by 2 lines计算由 2 条线给出的所有不规则形状的相交面积
【发布时间】:2020-07-03 07:55:11
【问题描述】:

我想问一些关于如何计算由 2 条线组成的不规则形状的相交面积。我一直在使用 shapely 来计算它可以工作的不规则形状,但如果我的形状相交,它就无法给出面积。

这是我需要计算面积的图像示例,其值有点像这样:

x1 = [636.021, 636.357, 636.692, 637.028, 637.364, 637.699, 638.035, 638.37, 638.706, 639.041, 639.377, 639.712, 640.047, 640.382, 640.717, 641.053, 641.388, 641.723, 642.058, 642.393, 642.727, 643.062, 643.397, 643.732, 644.066, 644.401, 644.736, 645.07, 645.405, 645.739, 646.073, 646.408, 646.742, 647.076, 647.41, 647.745, 648.079, 648.413, 648.747, 649.081, 649.414, 649.748, 650.082, 650.416, 650.75, 651.083, 651.417, 651.75, 652.084, 652.417, 652.751, 653.084, 653.417, 653.751, 654.084, 654.417, 654.75, 655.083, 655.416, 655.749, 656.021]
y1 = [34.19, 34.58, 34.58, 34.48, 35.8, 35.76, 35.35, 35.92, 36.44, 36.92, 36.73, 37.48, 37.98, 37.17, 39.01, 39.73, 39.7, 39.05, 38.72, 39.44, 39.81, 38.79, 38.56, 38.67, 38.62, 39.85, 39.11, 39.58, 39.38, 40.58, 39.71, 43.05, 42.68, 42.7, 42.48, 44.52, 45.36, 45.36, 46.82, 46.2, 46.48, 46.05, 46.92, 47.43, 47.74, 45.59, 46.83, 47.6, 47.04, 47.11, 47.63, 49.27, 49.19, 49.39, 49.57, 49.85, 51.45, 51.43, 51.26, 53.04, 51.96180180180196]
x2 = [636.021, 636.357, 636.692, 637.028, 637.364, 637.699, 638.035, 638.37, 638.706, 639.041, 639.377, 639.712, 640.047, 640.382, 640.717, 641.053, 641.388, 641.723, 642.058, 642.393, 642.727, 643.062, 643.397, 643.732, 644.066, 644.401, 644.736, 645.07, 645.405, 645.739, 646.073, 646.408, 646.742, 647.076, 647.41, 647.745, 648.079, 648.413, 648.747, 649.081, 649.414, 649.748, 650.082, 650.416, 650.75, 651.083, 651.417, 651.75, 652.084, 652.417, 652.751, 653.084, 653.417, 653.751, 654.084, 654.417, 654.75, 655.083, 655.416, 655.749, 656.021]
y2 = [40.84, 41.75, 41.43, 41.55, 42.19, 40.75, 41.51, 41.6, 40.68, 41.04, 41.16, 41.38, 41.41, 40.86, 41.51, 41.87, 41.53, 41.42, 40.82, 40.18, 39.8, 39.7, 38.75, 37.97, 38.69, 39.06, 37.39, 38.17, 38.69, 38.72, 37.75, 39.73, 39.0, 39.24, 40.28, 40.52, 40.27, 40.76, 41.15, 42.15, 41.7, 41.56, 40.79, 41.13, 42.76, 40.63, 40.71, 40.95, 41.24, 40.9, 40.77, 42.71, 42.05, 42.36, 41.91, 43.73, 43.64, 43.42, 43.2, 44.39, 43.4506606606608]

谢谢!

【问题讨论】:

  • 是不是你所有的 x 值在两行之间都是通用的?从您的数据中可以看出。如果属实,您可以轻松地对其进行数字积分...我认为。另外,你显示了交叉的线......你想要绝对区域(任何封闭区域)还是差异的积分,它们会在哪里偏移?
  • @Jeff H 是的,它来自实验数据的 2 行,x 值相同。是的,我想要任何封闭区域的绝对区域
  • 你为什么要使用 Shapely?
  • @Georgy 我正在使用 shapely 来查找 2 行的封闭区域。但是如果多边形区域相交,polygon.area 函数返回给我一个错误的区域值

标签: python polygon area shapely


【解决方案1】:

* 更正:这只适用于综合区域,不适用于“绝对区域”*

好的。我认为您的答案在于scipy.integrate,它可以通过梯形进行整合。这将起作用,因为您的 x 值是常见的,因此您可以只使用复合函数,例如 f(x) = y3 = y2 - y1。

#integrate trapezoids

from scipy import integrate

x1 = [636.021, 636.357, 636.692, 637.028, 637.364, 637.699, 638.035, 638.37, 638.706, 639.041, 639.377, 639.712, 640.047, 640.382, 640.717, 641.053, 641.388, 641.723, 642.058, 642.393, 642.727, 643.062, 643.397, 643.732, 644.066, 644.401, 644.736, 645.07, 645.405, 645.739, 646.073, 646.408, 646.742, 647.076, 647.41, 647.745, 648.079, 648.413, 648.747, 649.081, 649.414, 649.748, 650.082, 650.416, 650.75, 651.083, 651.417, 651.75, 652.084, 652.417, 652.751, 653.084, 653.417, 653.751, 654.084, 654.417, 654.75, 655.083, 655.416, 655.749, 656.021]
y1 = [34.19, 34.58, 34.58, 34.48, 35.8, 35.76, 35.35, 35.92, 36.44, 36.92, 36.73, 37.48, 37.98, 37.17, 39.01, 39.73, 39.7, 39.05, 38.72, 39.44, 39.81, 38.79, 38.56, 38.67, 38.62, 39.85, 39.11, 39.58, 39.38, 40.58, 39.71, 43.05, 42.68, 42.7, 42.48, 44.52, 45.36, 45.36, 46.82, 46.2, 46.48, 46.05, 46.92, 47.43, 47.74, 45.59, 46.83, 47.6, 47.04, 47.11, 47.63, 49.27, 49.19, 49.39, 49.57, 49.85, 51.45, 51.43, 51.26, 53.04, 51.96180180180196]
x2 = [636.021, 636.357, 636.692, 637.028, 637.364, 637.699, 638.035, 638.37, 638.706, 639.041, 639.377, 639.712, 640.047, 640.382, 640.717, 641.053, 641.388, 641.723, 642.058, 642.393, 642.727, 643.062, 643.397, 643.732, 644.066, 644.401, 644.736, 645.07, 645.405, 645.739, 646.073, 646.408, 646.742, 647.076, 647.41, 647.745, 648.079, 648.413, 648.747, 649.081, 649.414, 649.748, 650.082, 650.416, 650.75, 651.083, 651.417, 651.75, 652.084, 652.417, 652.751, 653.084, 653.417, 653.751, 654.084, 654.417, 654.75, 655.083, 655.416, 655.749, 656.021]
y2 = [40.84, 41.75, 41.43, 41.55, 42.19, 40.75, 41.51, 41.6, 40.68, 41.04, 41.16, 41.38, 41.41, 40.86, 41.51, 41.87, 41.53, 41.42, 40.82, 40.18, 39.8, 39.7, 38.75, 37.97, 38.69, 39.06, 37.39, 38.17, 38.69, 38.72, 37.75, 39.73, 39.0, 39.24, 40.28, 40.52, 40.27, 40.76, 41.15, 42.15, 41.7, 41.56, 40.79, 41.13, 42.76, 40.63, 40.71, 40.95, 41.24, 40.9, 40.77, 42.71, 42.05, 42.36, 41.91, 43.73, 43.64, 43.42, 43.2, 44.39, 43.4506606606608]

# compute y3 which is the difference between y2 and y1.

y3 = [t1 - t2 for (t1, t2) in zip(y2, y1)]

# integrate

trap_areas = integrate.cumtrapz(y3, x1)

# let's check the first one...

print(trap_areas[:3])

# area of first trapezoid
actual_area_first = (x1[1] - x1[0]) * 1/2 * ((y2[0]-y1[0]) + (y2[1]-y1[1]))

print(actual_area_first)

integrated_area = sum(trap_areas)

print(f'integrated: {integrated_area : 0.3f}')

产量:

[2.32176 4.67011 7.00867]
2.321760000000089
integrated:  654.699

【讨论】:

    猜你喜欢
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 2011-01-03
    • 1970-01-01
    • 2022-01-18
    • 2012-08-28
    相关资源
    最近更新 更多