title: intersection between line and closed curve
body: <p>I am trying to compute the intersection points between a line and a closed curve (stored in a file)</p>
  
  <p>I tried to adapt <a href="https://stackoverflow.com/questions/32351310/python-plot-intersection-of-line-and-data">this</a></p>
  
  <pre><code>import matplotlib.pyplot as plt
  from scipy.interpolate import interp1d
  from scipy.optimize import bisect
  import numpy as np
  import csv
  from scipy.interpolate import interp1d
  from scipy.optimize import bisect
  #reading curve from file
  r = ...
  z = ...
  
  
  # vertical line
  x = 1.885, 1.885
  y = [-3,3]
  
  
  
  z_ves = interp1d(r_ves, z_ves, fill_value="extrapolate")
  plt.figure(num=None, figsize=(10, 6), dpi=100, facecolor='w', edgecolor='k')
  plt.plot(r_ves, z_ves(r_ves))
  plt.axvline(x=1.885,ymin=-3,ymax=3)
  
  
  # #use interp1d to get interpolated points
  y = interp1d(x, y, fill_value="extrapolate")
  # stress = interp1d(strain, stress)
  # #set starting points
  x1 = max(x[0], r_ves[0])
  x2 = min(x[-1], r_ves[-1])
  max_err = .01
  # #create function
  f = lambda x : z_ves(x) - y(x)
  #find x1 where f(x1) = 0
  x1 = bisect(f, x1, x2, xtol = .001)
  y1 = z_ves(x1)
  #
  plt.figure(num=None, figsize=(10, 6), dpi=100, facecolor='w', edgecolor='k')
  plt.plot(r_ves, z_ves(r_ves))
  plt.plot(x, y(x))
  plt.scatter(x1, y1)
  plt.show()
  </code></pre>
  
  <p>I get a Runtime Warning as I think the line is vertical.</p>
  
  <blockquote>
    <p>RuntimeWarning: invalid value encountered in multiply
      y_new = slope*(x_new - x_lo)[:, None] + y_lo</p>
  </blockquote>
  
  <p>I know there are two intersections (see picture)
  <a href="https://i.stack.imgur.com/cRRHq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cRRHq.png" alt="enter image description here"></a></p>
  
  <p>how do I get the intersections?</p>