title: Bézier curve fitting with SciPy
body: <p>I have a set of points which approximate a 2D curve. I would like to use Python with numpy and scipy to find a cubic Bézier path which approximately fits the points, where I specify the exact coordinates of two endpoints, and it returns the coordinates of the other two control points.</p>
  
  <p>I initially thought <code>scipy.interpolate.splprep()</code> might do what I want, but it seems to force the curve to pass through each one of the data points (as I suppose you would want for interpolation). I'll assume that I was on the wrong track with that.</p>
  
  <p>My question is similar to this one: <a href="https://stackoverflow.com/questions/6299019/how-can-i-fit-a-bezier-curve-to-a-set-of-data">How can I fit a B&#233;zier curve to a set of data?</a>, except that they said they didn't want to use numpy. My preference would be to find what I need already implemented somewhere in scipy or numpy. Otherwise, I plan to implement the algorithm linked from one of the answers to that question, using numpy: <a href="http://inis.jinr.ru/sl/vol1/CMC/Graphics_Gems_1,ed_A.Glassner.pdf" rel="noreferrer">An algorithm for automatically fitting digitized curves</a> (pdf.page 622).</p>
  
  <p>Thank you for any suggestions!</p>
  
  <p>Edit: I understand that a cubic Bézier curve is not guaranteed to pass through all the points; I want one which passes through two given endpoints, and which is as close as possible to the specified interior points.</p>