简体   繁体   English

计算两条曲线到下一个交点的面积

[英]Calculate the area between two curves to the next intersection

I have two curves which intersect several times.我有两条曲线相交几次。 I don't know where the intersections are.我不知道交叉点在哪里。 I am trying to get a value for each area between two intersection points without manually setting the boundary.我试图在不手动设置边界的情况下为两个交点之间的每个区域获取一个值。

So far I calcualted the values of each curve and plot them with a green colour in case logifunc is above logifuncsoll and with a red colour if logifunc is below logifuncsoll.到目前为止,我计算了每条曲线的值并用绿色绘制它们,以防 logifunc 高于 logifuncsoll,如果 logifunc 低于 logifuncsoll,则绘制红色。

E701077['logifuncsoll'] = 1811.7/ (1 + 769.67 * np.exp(-0.704566*(xsoll)))+14.5212
E701077['logifunc'] = 1847.28 / (1 + 312.09 * np.exp(-0.606454*(x701077)))-8.16471


plt.figure(dpi=300)
plt.plot(x701077, E701077['logifuncsoll'],'r',markersize=np.sqrt(1), label ="soll",color='red' )
plt.plot(x701077, E701077['logifunc'],'r',markersize=np.sqrt(1), label ="E701077",color='purple' )
plt.legend
fig, ax = plt.subplots(1, 1, sharex=True)
ax.plot(x701077, E701077['logifunc'],linewidth=1 , label='logifunc', color= 'purple')
ax.plot(x701077, E701077['logifuncsoll'],linewidth=1, label='logifuncsoll', color='black') 
ax.fill_between(x701077, E701077['logifuncsoll'], E701077['logifunc'], where=E701077['logifunc'] >= E701077['logifuncsoll'], facecolor='green', interpolate=True)
ax.fill_between(x701077, E701077['logifuncsoll'], E701077['logifunc'], where=E701077['logifunc'] <= E701077['logifuncsoll'], facecolor='red', interpolate=True)
ax.legend(loc='upper left', frameon=False)

在此处输入图片说明

Total difference between the two lines is using scipy integrate the absolute value of the difference function.两条线之间的总差是使用 scipy 积分差函数的绝对值。

import scipy.integrate
left_lim = 0
right_lim = 27
func = lambda x: abs( (1811.7/ (1 + 769.67 * np.exp(-0.704566*(x)))+14.5212)-
(1847.28 / (1 + 312.09 * np.exp(-0.606454*(x)))-8.16471) )

area = scipy.integrate.quad(func, left_lim, right_lim)

To find the intersection points, use Shapely.要找到交点,请使用 Shapely。

import shapely
from shapely.geometry import LineString, Point

line1 = LineString(E701077['logifuncsoll'].values)
line2 = LineString(E701077['logifunc'].values)

int_pt = line1.intersection(line2)
point_of_intersection = int_pt.x, int_pt.y

print(point_of_intersection)

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

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