## Random cyclic curves

Princeton Press just sent me a review copy of a new book by Frank Farris called Creating Symmetry: The Artful Mathematics of Wallpaper Patterns. It looks amazing and I’m super excited to read it. Apparently John Cook has been reading it as well, and posted some Python code for generating this curve, which shows up towards the beginning of the book:

Mike Croucher also posted an interactive version using Jupyter notebook, where you can play with sliders to control the parameters of the curve and watch it evolve.

This is a plot of the parametric equation

$f(t) = e^{it} + \frac{1}{2} e^{6it} + \frac{i}{3} e^{-14it}$

in the complex plane. In general, Farris considers parametric equations of the form

$f(t) = \sum_j a_j e^{n_j it}$,

where $a_j$ are complex numbers, $n_j$ are integers, and as usual $i = \sqrt{-1}$. All such equations correspond to cyclic plots in the complex plane; he analyzes what sorts of symmetry they will have based on the parameters $n_j$.

He also spends some time talking about the aesthetics of picking values for $a_j$ and $n_j$ that result in beautiful curves. Instead of making carefully considered choices in this kind of situations, I often like to employ randomness to just generate a bunch of different instantiations and see what comes up (although there is still a certain amount of art in choosing the distributions for the random parameters). So, here are 50 random curves. Each one has

• Either 2, 3, or 4 terms
• Exponents chosen uniformly at random from $[-30, 30]$
• Coefficients chosen uniformly at random from the square in the complex plane from $-1 - i$ to $1 + i$.

I really like seeing these all together. They are not all great individually, but as a group, it’s fun seeing their differences, similarities, and idiosyncracies.

Don’t ask me what the parameters are for an individual curve because the program I used to generate them does not save the parameters anywhere! The code is here if you want to see it; of course it is written in Haskell and uses the diagrams framework.

Assistant Professor of Computer Science at Hendrix College. Functional programmer, mathematician, teacher, pianist, follower of Jesus.
This entry was posted in complex numbers, geometry, programming and tagged , , , , , . Bookmark the permalink.

### 24 Responses to Random cyclic curves

1. goldenoj says:

I’ve been interested in this all day, too. Here’s a GeoGebra version http://tube.geogebra.org/material/show/id/1292585

• Brent says:

Cool, thanks! Could you also make a version that lets you fiddle with the coefficients as well as the exponents? I think the curve changes much more smoothly with the coefficients (i.e. small changes in the coefficients result in small changes in the curve), which is not at all the case with the exponents, so playing with the coefficients might feel more satisfying because you can more directly get a sense for how dragging the sliders would affect the curve.

2. dfan says:

Are Spirographs still a thing? I made hundreds of pictures like this as a kid in the 1970s using one.

• Brent says:

They definitely are still a thing. I made lots of pictures with Spirograph as well when growing up.

This is both more general than Spirograph (since the different circular components can have different rates, not being limited to having to mesh via some teeth, and there can be more than two components) and also less general (there are only circular components, whereas Spirograph has other weird-shaped things as well).

3. goldenoj says:

That was groovy. (My daughter dared me to use that word.) Good suggestion!
http://tube.geogebra.org/material/show/id/1294967

• Brent says:

I agree, very groovy! =D

4. David says:

That’s another printable poster Brent, I like it!

“Mystery curve” is a hypotrochoid, no? At least the first 2 terms are, I think, and I assumed its mostly fair to call the 3 term version by the same name. I was playing with these a while back but didn’t understand how to pick coefficients & exponents that would always result in a curve with a small number of cycles. The complex form seems smarter and easier to understand & reason about than the parametric forms I usually see; looks like I need to read Farris’ book.

I dug up my lame attempts to map the space:

• Brent says:

Very cool animations!

Spirograph definitely generates hypotrochoids. I am actually not sure that the mystery curve is one. You can think of it as a linkage of circles, where the center of each circle is attached to the rim of the previous circle, and the circles are spinning at different rates. I don’t think that’s equivalent to a circle rolling around another circle. I aim to make an animation to demonstrate this soon.

5. Beautiful! Here’s a desmos version: https://www.desmos.com/calculator/s2jc5v0npm

• Brent says:

Thanks!

• David says:

Desmos is awesome! I made a tiny change and added sliders for the coefficients. Desmos lets you set ranges for your coefficients, and animate them too. I think n3 makes the coolest animation…

https://www.desmos.com/calculator/rdgq8cej6i

• Brent says:

Oh, that’s super cool. And I was totally wrong about small changes in the exponents not leading to smooth changes to the curve!

6. Nick says:

This got me inspired as well. Here’s one written in pure JavaScript:
http://wreck.wreckmath.com/games/parametric

• Brent says:

Oh, beautiful! I really like the little boxes that let you pick arbitrary *complex* values for the coefficients by dragging around points in the complex plane!

• David says:

Yeah, Nick, agreed – adding the phase to each coefficient is genius. 😉 I think it both helps you get a better feel for the space, and adds a great way to animate these things that is almost always interesting. With the default mystery curve parameters, I most enjoy dragging a2 in circles (adjusting only the phase), which causes all the loops to waltz around each other, like the Disneyland Tea Cups ride. I tried a little more animating building on your setup, by moving the coefficients in ellipses: https://youtu.be/myGXoLCnx-A

7. Pingback: Mystery curve | John D. Cook

8. Here is a collection, done with EMT.

Don’t know how to post code here.

• Brent says:

Cool, thanks! What is EMT? One easy way to post code is to upload it to a site like pastebin.com, and then share the link here. For short code snippets you can also put the code in between <code> … </code> tags.

• Euler Math Toolbox. I posted the code in its Forum. See

http://forum.euler-math-toolbox.de/viewtopic.php?t=185&p=712#p712

By the way, the curves should be computed with adaptive evaluation. EMT has a function for this. But due to laziness, I just took 5000 points around the circle. I think I will post a blog entry about this in my blog (observations.rene-grothmann.de).

• Okay, just the lazy code with 5000 points:

 >function plotone (a:vector,f:vector,r=none,grid=0,thickness=1) ... $t=linspace(0,2*pi,5000);$ z=exp(I*t)+sum((a'*exp(I*f'*t))')'; $if r==none then r=totalmax(abs(z))*1.05; endif;$ plot2d(re(z),im(z),=r,=grid,=thickness); \$endfunction >plotone([1/2,I/3],[6,-14],thickness=0.7):