title: joining two Bézier curves smoothly (C2 continuous)
body: <p>(Follow-up of <a href="https://stackoverflow.com/questions/8989440" title="this question">this question</a>.)</p>
  
  <p>Given a sequence of cubic Bézier curves, how can I modify them minimally to make them join in a C2-continuous way?</p>
  
  <p>Input:</p>
  
  <ul>
  <li>curve P with control points <code>P0</code>, <code>P1</code>, <code>P2</code>, <code>P3</code></li>
  <li>curve Q with control points <code>Q0</code>, <code>Q1</code>, <code>Q2</code>, <code>Q3</code></li>
  <li>if it helps, you can assume that they are already C1 continuous.</li>
  </ul>
  
  <p>Constraints:</p>
  
  <ul>
  <li>C0 continuity: <code>P3 = Q0</code></li>
  <li>C1 continuity: <code>P2 - P3 = Q0 - Q1</code></li>
  <li>C2 continuity: <code>P1 - 2*P2 + P3 = Q0 - 2*Q1 + Q2</code></li>
  <li>modified curves as close as possible to original curves P and Q</li>
  </ul>