Mastering the Adobe Illustrator pen tool is a fundamental skill of any professional graphic designer. It’s essential when you’re designing vector-based images and fonts. Most designers use intuition to decide when a curve looks or “feels” right. But sometimes it just looks odd and you can’t figure out why. Should you put in another anchor? Take one out?
There’s actually a science behind curves. In this article I’ll explain the math behind curves, and show you how to use it to make your curves look smoother and more aesthetically pleasing.
A common technique in professional CAD and font design software is to use a visualization called a curvature comb to see how sharp or flat a curve is along its path.
Here’s an example of a curvature comb being used in Fontlab VI to smooth out bumpy spots in a font:
The curvature comb is the amber-colored bit at the edge of each curve. As a designer you can use the size of the comb to judge how curvy the line is and where there are discrepancies in the curve. (Notice in the above gif how the curve gets smoother as the amber and red bits line up.)
To explain how this visualization works, we’ll need to take a quick look at how Bézier curves work.
Cubic Bézier curves
Bézier curves were originally invented independently by two French engineers working in the automotive industry—Paul de Casteljau from Citroën and Pierre Bézier working for Renault. These curves turned out to be very useful for designing the curved and aerodynamic shapes necessary in automotive design.
Since their invention, Bézier curves have been expanded to all kinds of applications including aerodynamics, animation and computer graphics.
Most vector graphics software such as Adobe Illustrator uses cubic Bézier curves to display curved lines.
A cubic Bézier curve is defined by four points: P₀, P₁, P₂ and P₃. The curve starts at P₀ moving toward P₁ and arrives at P₃ coming from the direction of P₂. Drag the slider below to see what that looks like in motion:
The position along the curve can be calculated with the formula:
It might look a bit complicated—but don’t worry—I’ll explain.
The idea is that it’s kind of “blending” between the control points P₀, P₁, P₂ and P₃ as t goes from 0 to 1.
Think about this curve like a road. You’re at P₀ and need to get to P₃, but it’s on the other side of the mountain, so you have to travel on a curved road around the outside. At the start, you leave your starting position at P₀ and start driving in the direction of P₁ gradually turning towards P₂ and then finally towards P₃.
The first derivative of the curve describes the slope of the tangent of the curve.
Thinking back to our driving example above, this relates to where your tires are pointing (which is controlled by how much your wheel is turned) at any give moment on your journey. When you start out, your tires probably point pretty much straight ahead. As you make your way around that big bend, however, you turn the wheel to point your tires at a sharper angle (or risk driving off a precarious cliff).
The first derivative is also used to calculate the line that is 90º to the curve—sometimes called the normal. If you were to put your arm out the car window, this would be that direction.
The second derivative of the curve is:
This is starting to get a bit more abstract… but essentially the second derivative describes how quickly the tangent is changing.
Hopping back into our car: if the first derivative is where our tires are pointing, the second is how much you have to turn the wheel to get it to point in the proper direction. Closer to P₀ you’d just turn the wheel a bit and hold it steady to maintain your path, but as you enter the hairpin turn at around t=0.5, you really have to crank the wheel hard (changing of the angle of the tires faster) to make sure you stay on the road. The faster you turn the wheel (versus just holding it steady) is a demonstration of the second derivative.
Curvature is a measure of how “sharply” a curve is changing. It’s similar to the second derivative above, but it’s adjusted to take into account how curves look in 2D.
Flat spots have a low curvature—for example, a straight line has a curvature of 0. Sharper areas have a higher curvature. Usually the curvature will change as you go along a Bézier curve.
To measure the curvature of a cubic Bézier curve we’ll use a technique I found described in Computer Aided Geometric Design course notes. The idea is to try and fit a circle inside the curve at each point, so that the circle just barely touches. Mathematicians call this an osculating circle, which in latin means “to kiss”. 😘
As you can see, where the curve is “sharper” the radius of the circle is smaller. And where the curve is gentler, the circle is smaller. In other words, the curvature is calculated as the inverse of the osculating circle’s radius.
By drawing normal lines at a regular interval with a length based on the curvature, we now have our curvature comb:
This curvature comb is a useful tool to see which parts of the curve are “sharper” (where the combs’ teeth are longer) or “flatter” (where they’re shorter).
If you’re designing anything more complicated than a quarter circle, you’ll inevitably need to join multiple curve segments together. This introduces challenges if you want keep your shapes looking smooth at all the points where the curve segments connect.
Try dragging the slider above—it moves the point that connects two Bézier curves.
When the amount of curvature at the joining point doesn’t match, you might notice it can look kind of “lumpy”. This is because the curve is suddenly jumping from one curvature to another. These sudden jumps in curvature are called continuity breaks.
Try moving the slider until the amount of curvature lines up on both sides.
Ahh, much better! 😌