简体   繁体   English

平面上相交点之间的曲线面积

[英]Area of a curve between intersection points on a plane

I have a curve generated by random and a line which runs through it. 我有一条由随机产生的曲线和一条贯穿其中的线。 I have found the intersection coordinates of the curve with the line using interpolation. 我使用插值法找到了曲线与直线的相交坐标。 But now I have to find the areas of the curves between these points. 但是现在我必须找到这些点之间的曲线区域。 My code is as follows: 我的代码如下:

import numpy as np
import matplotlib.pylab as pl
from matplotlib import mlab
def find_inter_coord(a,x):
    y = a-x
    index = mlab.find((y[1:] >= 0) & (y[:-1] < 0)| (y[1:] < 0) & (y[:-1] >= 0))
    crossing_index = [i - y[i] / (y[i+1] - y[i]) for i in index]
    return crossing_index
data = np.random.uniform(low=-1000, high=-200, size=(100,))
pt = -750.5
pt_array = (pt) * 100
x = find_inter_coord(data, pt)
pl.figure(figsize = (10,5))
pl.plot(data)
pl.plot(pt_array)
pl.scatter(x, [pt for p in x], color='red')

The graph is as follows: 图形如下:

输出图 Now I need to find the areas of all the curves below the line pt_array.. How do I do this? 现在,我需要找到线pt_array下面的所有曲线的面积。我该怎么做? Any help would be aprreciated. 任何帮助将不胜感激。 thanks 谢谢

To find the areas of the curves, you can implement the following steps: 要找到曲线的面积,可以执行以下步骤:

  1. Find all the points that are below the line (green dots). 查找线下的所有点(绿色点)。
  2. For each pair of intersection points, if there are points that are below the line between them, do the following: 对于每对相交点,如果它们之间的线下方有一些点,请执行以下操作:
    1. Compute the area of the triangle up to the first data point under the line (Areas marked A ) 计算三角形的面积,直到该线下的第一个数据点(标为A的面积)
    2. Compute the areas of all the trapezoids between successive points (Areas marked B ) 计算连续点之间所有梯形的面积(标为B的面积)
    3. Compute the area of the triangle between the last point under the line and the next intersection (Areas marked C ) 计算线下最后一个点和下一个相交之间的三角形面积(标为C的面积)

在此处输入图片说明

The area of a triangle between intersection point (x i , pt) and sub-line point (x j , y j ) (areas marked A ) is just 0.5 * (x j - x i ) * (pt - y j ) . 交点(x i , pt)和子线点(x j , y j )之间的三角形面积(标记为A的区域)仅为0.5 * (x j - x i ) * (pt - y j ) For areas marked C , just reverse the order of the x coordinates. 对于标记为C的区域,只需反转x坐标的顺序即可。

The area of a trapezoid between two sub-line points (x i , y i ) and (x j , y j ) (areas marked B ) is 0.5 * (x j - x i ) * (y i + y j ) 两个子线点(x i , y i )(x j , y j ) (标为B的区域(x j , y j )之间的梯形面积为0.5 * (x j - x i ) * (y i + y j )

The areas A, C on the right show a corner case you may or may not need to handle differently, where there are no trapezoidal regions between the triangular ones. 右侧的A,C区域显示了一个拐角处,您可能需要也可能不需要进行其他处理,在三角形之间没有梯形区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM