Bézier Curves!!!
- #math #graphics #art
- 229 words, Read time 1 minute, 9 seconds
This one comes from building the Pseudo 3D project. I wanted a part of it to be freely customizable, and the cleanest way to hand someone that kind of control is to let them drag a curve around. So I ended up implementing a Bézier editor in Qt.
A Bézier curve is a smooth line defined not by every point along it, but by a handful of control points. Place the points, and the curve bends toward them without necessarily touching them. Drag a control point and the whole curve reflows. It is the same math behind font outlines, animation easing, and the pen tool in every design app.
The trick underneath is surprisingly elegant: you take linear interpolations of linear interpolations. Blend between two points to get a moving point, nest that a few times, and the curve falls out for free.
The number of control points sets the order. A linear Bézier is just a straight line between two points. A quadratic adds one control point in the middle. A cubic uses two, which is the sweet spot most tools land on, because two handles let you shape the tangent at each end independently. Enough freedom to draw almost anything, cheap enough to compute in real time.
I did not learn this from a textbook. I learned it here. The math for this is genuinely, amazingly simple.