![](/img/trans.png)
[英]How to calculate distance between a point and an intersection line in python?
[英]Calculate intersection between a line and a interpolation
我想计算直线和插值函数之间的交点。 我可以绘制插值以及图中的线:
import matplotlib.pyplot as plt
import numpy as np
import scipy.interpolate as scp
y = [ 815.97, 815.95, 815.98, ..., 815.9] #60 elements
x = [405383892, 405383894, 405383895, ..., 405383896] #60 elements
mediana = np.median(x)
f = scp.interp1d(x,y,bounds_error=False,fill_value=0.,kind='cubic')
new_x_array = np.arange(min(x),max(x),0.01)
plt.figure()
plt.plot(new_x_array,f(new_x_array),'r-')
plt.plot([x[0],x[59]], [mediana,mediana], 'g-')
plt.plot(x, y, 'mo')
但是,我没有找到计算红色功能和绿线之间的交叉点的方法。 找到两者之间的交叉点的常用方法是什么?
interp1d在数据点之间进行样条插值。 据我所知,scipy中没有一种方法可以为你提供所有这个插值的域,但是因为它的样条插值可以解决这个问题。
您可以执行以下操作。
因此,对于低样条顺序,这应该是直截了当的。
感谢您的回答! 我将来会使用该解决方案。 最后我解决了它寻找接近插值线的值:
index=[]
for pos in range(0,len(new_x_array)-1):
if (mediana > f(new_x_array[pos])) & (mediana < f(new_x_array[pos+1])):
index.append(new_x_array[pos])
if (mediana < f(new_x_array[pos])) & (mediana > f(new_x_array[pos+1])):
index.append(new_x_array[pos])
索引数组的位置靠近该行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.