问题描述
我试图找到直线(红色虚线)与等高线以红色突出显示的交点(请参见图)。我在第二个绘图中使用.get_paths将所述轮廓线与其他轮廓线隔离(第二个绘图)。
I am trying to find the intersection point of a straight(dashed red) with the contour-line highlighted in red(see plot). I used .get_paths in the second plot to isolate said contour line form the others(second plot).
我看过轮廓交点问题,,并尝试将其用作基础但无法复制任何有用的内容。
I have looked at a contour intersection problem, How to find all the intersection points between two contour-set in an efficient way, and have tried to use it as a base but have not been able to reproduce anything useful.
有人有什么想法吗?
用于重新创建图的相关函数,
relevant functions to recreate plot,
可以找到交点,而不是使用该点作为 fsolve()的初始猜测值找到真正的解决方案:Use shapely can find the intersection point, than use the point as the init guess value for fsolve() to find the real solution:
#for contour def p_0(num,t) : esc_p = np.sum((((-1)**n)*(np.exp(t)**n)*((math.factorial(n)*((n+1)**0.5))**-1)) for n in range(1,num,1)) return esc_p+1 tau = np.arange(-2,3,0.1) x,y= np.meshgrid(tau,tau) cs = plt.contour(x, y, np.log(p_0(51, y)/p_0(51, x)),[0.2],colors='k') p=0.75 logp = (np.log(p*np.exp(tau))) plt.plot(tau,logp) from shapely.geometry import LineString v1 = cs.collections[0].get_paths()[0].vertices ls1 = LineString(v1) ls2 = LineString(np.c_[tau, logp]) points = ls1.intersection(ls2) x, y = points.x, points.y from scipy import optimize def f(p): x, y = p e1 = np.log(0.75*np.exp(x)) - y e2 = np.log(p_0(51, y)/p_0(51, x)) - 0.2 return e1, e2 x2, y2 = optimize.fsolve(f, (x, y)) plt.plot(x, y, "ro") plt.plot(x2, y2, "gx") print x, y print x2, y2这是输出:
0.273616328952 -0.0140657435002 0.275317387697 -0.0123646847549和情节:
这篇关于寻找直线和轮廓之间的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!