3 ms·
I enjoyed reading it, but I wouldn't call it a "primer", since I can hardly think of what else there is to know about Bezier curves! It's a rather comprehensive
by romwell 7y ago
I enjoyed reading it, but I wouldn't call it a "primer", since I can hardly think of what else there is to know about Bezier curves! It's a rather comprehensive exposition.
Here's a primer on Bezier curves if you had to program them in 30 minutes. You won't need more than this:
1. Bezier curves are just taking weighted averages, repeatedly. A weighted average of two points, A and B, is a linear combination P(t) = (1-t)A + tB. As t goes from 0 to 1 with constant speed, P(t) goes from A to B with constant speed.
A weighted average like this gives you one point out of two. Now, say you have four points, in order: A1, A2, A3, A4. For a number t between 0 and 1, take weighted averages of consecutive points: A1 and A2, A2 and A3, A3 and A4. That gives you a sequence three points. Repeat this procedure until you have only one point left. That's your Bezier curve defined by A1..A4 at time t. This is called a 3rd degree curve, and generalizes to sequences of any length (you can figure out how!).
2. The above tells you how to draw this with a computer. Just pick, say, 100 values of t between 0 and 1, and connect the dots with straight lines. That is, you converted a curve into a poly-line, consisting of straight segments. This can be used to compute intersections (just see if any one segment intersects any other), compute tangents (extend any segment to get a tangent at that point), normals (in 2D: rotate a segment by 90 degrees clockwise).
3. Most importantly, why you would want to do something like this: Bezier curves are easy for machines to trace, and for humans to understand. Here are some properties of a (cubic) Bezier curve given by points A1, A2, A3, A4:
-it starts at A1, and ends at A4
-it is tangent to segments A1A2 and A3A4 at endpoints
-by moving A2 and A3, it is easy to make a C- and S- shaped curve.
Beyond that, things aren't as intuitive. This is why all graphics software gives you 3rd degree Bezier curves as a tool: it's flexible enough while easy enough.
In practice, Bezier curves came to replace the French Curve[1]. The irony is that there is little French about the French curve (nobody even knows why they're called that!), but Bezier curves are French through and trough: the two key people behind them, Paul de Casteljau and Pierre Bezier, have spent their entire lives in France, and came up with the curves for manufacturing at Citroen and Renault. Arguably, Bezier curves are the true French curves.
4. Bonus. In Photoshop/Illustrator/etc: the UI for Bezier curves is this: click and drag to define A1 and A2 (A1 is is where you click, A2 is where you release). Consecutive click-drag-releases define three points: e.g. A3 on mouse down, A4 on mouse up, and A5 such that A4 is the midpoint of A3 and A5. The curve you get is a union of cubic Beziers defined by A1..A4, A4..A7, A7..A10, etc.
The curve is smooth because the UI forces the tangents to be aligned (unless you do a single click without dragging: this makes 2 tangents of length 0, i.e. a vertex).
When drawing curves using this UI, you really are drawing tangents to the curve you want to get: draw _— to get an S, roughly.
That's it folks! For way, way more - read the article :) (Which is an interactive book, at this point).
[1]https://en.wikipedia.org/wiki/French_curve https://en.wikipedia.org/wiki/French_curve
- sweeneyrod 7y ago> 2. The above tells you how to draw this with a computer. Just pick, say, 100 values of t between 0 and 1, and connect the dots with straight lines. This is the obvious algorithm, but it has the problem that curvature is not uniform with respect to t - sometimes a straight line is a good approximation to a segment but sometimes it isn't. So instead you can draw a curve with a function that draws a straight line when that's good enough, and splits the curve in two then recurses on each half otherwise.
- romwell 7y agoGood point! It's hard to make a call as to what to do include in a 5-minute overview, but your point fits in one sentence, and is easy to understand. Thanks!
- TheRealPomax 7y ago"all" graphics software is quite the sweeping statement. One of the most common graphics languages used in every day life by everyone on a computer, is the truetype graphics language, used to define vector graphics for one of the two major flavours of openetype font. TTF only does quadratic curves, and is ubiquitous. There are also plenty of CNC packages that don't even give you Bezier curves at all, and I would definitely consider those graphics software. As for the book no longer being a primer: just because it's longer than a few pages, doesn't mean it's not a primer anymore =) It's currently about 100 pages, so essentially what you'd be expected to read "before the next class" in university, which is my standard for what a primer is: a primer should get you complete understanding at the fundamental level. Anything less and it's not going to prime the reader for further study. So it speaks to the subject of Bezier curves that you can have 100 pages and _still_ be just a primer on the subject. If I wanted it to be exhaustive, it'd probably be at least twice the current size (now... we might get there eventually, but not any time soon!) As such I also wouldn't consider this description a "primer" but more of a short descriptiong: it correctly describes de Casteljau's algorithm, but the drawing algorithm is not the curve type, and doesn't really work in terms of getting people to understand Bezier curves themselves (unless they're scarily good at internalising just an algorithm description and then abstracting all the implications of that algorithm without further aid =)