title: Line and curve intersection in python using bezier curve and vertical line
body: <p>I have a Bezier curve and am trying to intersect it with a vertical line. I don't have a background in maths so I was hoping to find the point of intersection using an intersection function without having to solve line equations. Any help would be greatly appreciated!</p>
  
  <p>Here is what I have so far</p>
  
  <pre><code>#!/bin/python
  
  import matplotlib.pyplot as plt
  from matplotlib.path import Path
  from matplotlib.lines import Line2D
  import matplotlib.patches as patches
  import matplotlib.ticker as plticker
  import numpy as np
  
  from matplotlib import cbook
  
  from shapely.geometry import LineString, Point
  
  verts = [
      (0., 0.),  # P0
      (0, 100), # P1
      (100, 0), # P2
      (100, 100), # P3
      ]
  
  codes = [Path.MOVETO,
           Path.CURVE4,
           Path.CURVE4,
           Path.CURVE4,
           ]
  
  path = Path(verts, codes)
  
  fig = plt.figure()
  ax = fig.add_subplot(111)
  patch = patches.PathPatch(path, facecolor='none', lw=2, picker=0)
  
  #add the line
  ax.add_patch(patch)
  
  xs, ys = zip(*verts)
  #add the handles lines
  #ax.plot(xs, ys, 'x--', lw=2, color='black', ms=10)
  
  #ax.text(1, 1, 'P0')
  #ax.text(20, 4, 'P1')
  #ax.text(96, 80, 'P2')
  #ax.text(96, 96, 'P3')
  
  ax.set_xlim(-0.1, 100.1)
  ax.set_ylim(-0.1, 100.1)
  
  intervals = float(5)
  loc = plticker.MultipleLocator(base=intervals)
  ax.xaxis.set_major_locator(loc)
  ax.yaxis.set_major_locator(loc)
  ax.grid(True,'both')
  
  #################
  
  print ""
  #print zip(*path.iter_segments(stroke_width=10.0,curves=False))
  
  def on_move(event):
      #thisline = event.artist
      xmouse, ymouse = event.xdata, event.ydata
      #print "x: ", str(xmouse), ", y: ", str(ymouse)
  
  def on_click(event):
      xmouse, ymouse = event.xdata, event.ydata
      print xmouse
      newline = Line2D([xmouse,xmouse], [0,100])
      ax.add_line(newline)
      fig.canvas.draw()
  
  fig.canvas.mpl_connect('motion_notify_event', on_move)
  fig.canvas.mpl_connect('button_press_event', on_click)
  
  ###############
  
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/0B6sl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0B6sl.png" alt="here is the graph"></a></p>