[英]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: 要找到曲线的面积,可以执行以下步骤:
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.