This is true of pretty much anything, really. Learning how a system works? Program it. Tinker with it. It’s the difference between looking at diagrams about how to tie your laces and actually practising with your hands.
Bézier curves are a nifty way of representing curves. This website is a fantastic overview of them and their surrounding topics, and I highly recommend it if you want to learn more, because this is just a write-up of an afternoon coding project I undertook recently and isn't going to go into anywhere near as much detail. (Moreover, that site has interactive diagrams and curves, which I don’t know how to do yet. Soon, though. Soon.)
They’re not very intimidating things, really - just polynomials manipulated by a set of ‘control points’. Look:
All Bézier curves are like this, having a start point, an end point, and bunch of points in between. If you were to draw lines sequentially joining up all the control points, the curve would fit within the shape formed by those lines.
You know how to do linear interpolation, right? It's basically just that. But not linear. So instead of this:
Simply put, for each control point, we warp the curve by a certain amount. The 'order' of the curve is equal to its number of control points minus one. A curve with only 2 control points isn't much of a curve at all - it's a straight line, of order 1, it is linear. With 3 control points we get an order 2 (quadratic) curve. With 4 we get an order 3 (cubic) curve. And so on.
At each iteration, before we add in the control point's position to the sum, we multiply it by the binomial coefficient for the order of the curve and the current term we're on, i. This is done by just looking up the value in Pascal's triangle at (order, i). After that we multiply by the polynomial section of the formula, (1 - t)^(order-i) * t^i, and we're ready to move on to the next iteration.
- Left click: place a new control point. The new point becomes the second point in the curve's list of points.
- Left click and hold over an existing point moves the point around.
- H: hide or reveal the text.
- Up arrow, down arrow: increase or decrease the number of segments.
- R: reset the curve. Removes all the control points.
You can download a (hopefully functional) copy of this very simple program below. Enjoy!