title: calculating intersection point of quadratic bezier curve
body: <p>This is definitely pushing the limits for my trig knowledge.</p>
  
  <p>Is there a formula for calculating an intersection point between a quadratic bezier curve and a line?</p>
  
  <p><strong>Example:</strong></p>
  
  <p>in the image below, I have P1, P2, C (which is the control point) and X1, X2 (which for my particular calculation is just a straight line on the X axis.)</p>
  
  <p>What I would like to be able to know is the X,Y position of T as well as the angle of the tangent at T. at the intersection point between the red curve and the black line.</p>
  
  <p><img src="https://i.stack.imgur.com/2w9u0.png" alt="curve example"></p>
  
  <p>After doing a little research and finding <a href="https://stackoverflow.com/questions/5634460/quadratic-bezier-curve-calculate-point" title="info">this</a> question, I know I can use:</p>
  
  <pre><code>t = 0.5; // given example value
  x = (1 - t) * (1 - t) * p[0].x + 2 * (1 - t) * t * p[1].x + t * t * p[2].x;
  y = (1 - t) * (1 - t) * p[0].y + 2 * (1 - t) * t * p[1].y + t * t * p[2].y;
  </code></pre>
  
  <p>to calculate my X,Y position at any given point along the curve. So using that I could just loop through a bunch of points along the curve, checking to see if any are on my intersecting X axis. And from there try to calculate my tangent angle. But that really doesn't seem like the best way to do it. Any math guru's out there know what the best way is? </p>
  
  <p>I'm thinking that perhaps it's a bit more complicated than I want it to be.</p>