[SciPy-User] How to find the intersections between two lines

seasoul bioseasoul@gmail....
Thu Apr 8 23:15:37 CDT 2010


This is my first post in the mailing list.
I want to find the intersections between two lines. One line is an arbitrary
straight line, the other is a fitting line created by a interpolation
procedure.
Below is a simple code:


x = linspace(0,10,20)
y = rand(20)*10
plt.plot(x,y,'o')
f = interpolate.interp1d(x,y,kind=5)
xx = linspace(0,10,100)
yy = f(xx)
plt.plot(xx,yy,'r-')
y2 = x
plt.plot(x,y2,'b-')
def func(x):
   out = [x[1]-x[0]]
   out.append(x[1]-f(x[0]))
   return out
fsolve(func,[1,1])

The fitting line is a polynomial curve, the straight line is y=x. This
function can only find one of the intersection points,not all.

I tried to use x[:,1] and x[:,2], and hope in the function func, the
operation is element-by-element, but some errors came out.
Any help is appreciated.

The output figure:

 http://picasaweb.google.com/lh/photo/vJZRP6tAmmhpIh4J2BG0-g?feat=directlink
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20100409/c28e748a/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 4.png
Type: image/png
Size: 33435 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/scipy-user/attachments/20100409/c28e748a/attachment-0001.png 


More information about the SciPy-User mailing list