Fourier Curves

Fourier Curve 1

Don’t let the title put you off — this is one of the coolest things I’ve seen in a while. It’s because of math, but there’s no need to get all mathy to enjoy this, you just need to think about clocks. Or even wheels that spin ’round and ’round.

The fun thing is what happens when we connect one wheel to another in a chain of wheels of different sizes and turn rates. If we use the last wheel to trace out a pattern, we get something that resembles the Spirograph toy of old (which worked on a similar principle of turning wheels).

And if we pick the wheel sizes and spin rates just right, we can draw just about any picture we want.

Here’s the star of the show. Kick back and enjoy this amazing video. Watch it on the biggest screen you have. As you watch, realize that it’s all being done with nothing more than different sized-wheels turning at different rates.

Each turning arrow in the video is what I’ve been calling a “wheel” — you can see the arrows come in different sizes and that they turn at different rates.

If it’s not obvious, the tail of the next arrow starts at the tips of the previous arrow. The tips and tails remain connected at all times while the arrows spin.

The amazing bottom line here is that any line drawing (consisting of a single curve) can be reduced to some specific series of these “wheels” — which can be various sizes (amplitudes) and can spin at different rates (frequencies).

Put another way: Any continuous line drawing consists of a specific series of sine waves.

You see the principle in action in the animation.

Here’s an excellent video that explains this in detail:

(It’s all by 3Blue1Brown, one of the best mathematics YouTube channels I’ve found. I’m already indebted due to his videos on quaternions.)

§ §

If you like, you can just enjoy that first video and leave it at that. From here on I’m going to get a bit more into the weeds.

(I’ll connect it with how JPEG compression works, if that interests you.)

§

Fourier Curve 2

I was very taken by this and realized it would be pretty easy to write a simple version I could use to explore the effects of different wheels.

The image at the top of this post is one example, the image to the right here is another (click on any of these for a big one).

I made these simple versions using just six wheels, and even so the degree of variation seems all but endless.

Each wheel has a “size” (amplitude) — the length of the arrow — and a rate of spin (frequency), which can be clockwise or counter-clockwise (positive or negative).

I can also control the starting point of each wheel (phase). The default is that each arrow starts off pointing left. The phase setting lets the arrow start in any position around the wheel.

So, six wheels times three settings each (amplitude, frequency, phase) gives me 18 parameters to play with.

§

Fourier Curve 3

Just to show how much different parameters change the pattern, here’s a third example I found by playing.

Here you can start to see how this technique could actually create a line drawing (it sort of looks like a weird triangular turtle).

This is with just six wheels — the video uses a lot more!

We draw these curves on the complex plane, which lets us leverage how complex numbers link multiplication and rotation. Our “spinning arrows” are nothing more than complex numbers repeatedly multiplied by a rotation.

Linking the arrows, tip to tail, is just a matter of adding the complex numbers, because on the complex plane addition is vector (arrow) addition.

This makes the code surprisingly simple.

§

What makes all this work is how many continuous systems can be analyzed in terms of sine waves.

Any sound, for example, is comprised by a set of sine waves. And any sound can be created by adding the right set of sine waves.

Likewise, any continuous 2D curve is comprised of sine waves, and any curve can be created by adding sine waves.

For example, here are the “sound waves” created by using the same three sets of “wheels” (sine waves) I used to create the three images above:

Fourier Sound Wave 1

Fourier Sound Wave 2

Fourier Sound Wave 3

In this case, just the arrow tips are added together (not laid tip to tail) to create a single arrow that traces the “sound wave.”

The interesting thing is that the 2D patterns are, in a sense, contained in these “sound waves” — which I’d love to hook up to a DAC and hear. They obviously have a base frequency with harmonics.

It would also be true that the set of sine waves used to draw the figures in the video would create a sound wave. That would be quite interesting to hear.

§

You may not realize that JPEG compression uses something vaguely similar.

The technique is different, but a JPEG image is a collection of sets of sine waves.

Essentially, each image plane (red, green, blue) is broken into small squares, and those squares are analyzed to determine what set of “visual sine waves” best comprise the elements of the square. [See the Wiki article for details.]

It’s this technique that results in JPEG images being “lossy,” because they’re actually constructed from sine waves, and the whole point is to save size by not using all the upper harmonics (because our eye-brain system can be tricked).

This also why lowering the compression to improve quality makes the file size bigger: improving quality means adding more and more upper harmonics.

Update July 11, 2019, 11:20 CST: I forgot to include this Computerphile video that does a nice job of explaining how JPEG compression works:

(I’d forgotten that RGB is converted to YCbCr so that color information can be compressed more than grayscale information!)

§ §

This Fourier business is one of those huge leaps forward for science. It has applications anywhere there is a periodic, continuous process.

It’s huge in anything involving waves. (When the ocean waves, wave back!)

And it can be used to draw pictures in a way that’s very cool to watch.

Stay sinuous, my friends!

About Wyrd Smythe

The canonical fool on the hill watching the sunset and the rotation of the planet and thinking what he imagines are large thoughts. View all posts by Wyrd Smythe

2 responses to “Fourier Curves

And what do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: