From fonts to animated movies, curves and surfaces constitute fundamental building blocks of many geometrical designs. Over the course of this blog post I’ll explain how this model of a mask can be very smooth despite being described by a limited number of small points that you can drag around to change the mask’s shape:
Moreover, we’ll see how surfaces like that are a natural extension of plain two dimensional curves like the one below:
Throughout this article I’ll keep jumping back and forth between curves and surfaces to highlight how the ideas we develop for wiggly lines can be expanded onto three dimensional shells that we can shape.
Before we build complicated curves and surfaces we first have to decide how we’d like to control their shape. There are many ways to describe and mold these objects, but some of those ways are better than others. In the demonstration below I built a system that lets you change the shape of a curve by controlling its spiral‑ness and size:
While fun to play with, this system is quite impractical. We can’t control where exactly the curve ends and we also have a very limited influence on how it twists. For instance, it’s impossible to create an S‑shaped curve using these controls.
Ideally, we’d deal with a system that would let us directly affect where the curve is placed, while also providing a convenient control over its entire shape. These are the features that control points provide. Their visual placement makes it very easy to define the shape of a curve. In the demonstration below you can drag each control point shown as to change the curve’s form:
Control points are often visualized with connecting lines that join them to their neighbors. This helps to avoid ambiguities when two different points swap their positions which can make the curve look quite different.
Notice that all control points seem to affect the shape of the curve in the point’s vicinity. We can visualize the impact of a given point using red color. In the demonstration below you can click a control point to see how it affects the local shape – the redder the section of the curve the more influenced it is by that control point. Gray sections don’t move at all when the selected point is dragged:
With control points we can easily change where the curve starts, ends, and how it flows in the middle. Moreover, the shape of the lines connecting the control points roughly resembles the shape of the resulting curve. This system of control points is simple, yet very powerful.
So far I’ve been quite vague about the rules driving the shape of the resulting curve and the extent to which the control points affect it. I’ll try to explain those underlying principles by building this system from a ground up. We’ll also see how those ideas extend to surfaces, but before we construct these more complex elements we’ll start with the simplest curve – a linear segment.
In the demonstration below you can drag the control points A and B around to change their position. The slider controls a virtual red pen that is used to draw a segment between those two points:
While this demo is the world’s most primitive drawing application, there are some important observations we can make here already. The slider controls the progress of our drawing – the more advanced the slider is the further into drawing we are. For the progress of 0.5 we’re halfway through a drawing, and at the progress of 0.9 we’re mostly done.
Additionally, a point on the segment very close to point B, as shown by the tip of the pen, moves very little when point A is dragged, but it moves a lot when point B is dragged.
We can visualize the “weight” of a given control point on the curve using the red tinting we’ve seen before. You can click the control points to change which one is selected:
For a linear segment like that, weighting function is quite straightforward. The closer to the control point we are the more impactful it is. Let’s try to put some numbers behind these dependencies.
There are many ways to specify the impact of a control point at a distance, but the simplest approach is to assume that those weights are changing proportionally with that distance. As we progress through the curve using the slider we decrease the weight of the point A and increase the weight of the point B:
This hopefully makes intuitive sense. When we’re all the way through the curve the weight of the point A is 0 and we can move it around all we want without affecting the position of the end of the curve.
We can describe those little plots using some equations. A word “progress” would make the formulas very long so I’ll replace it with the traditionally used letter t: