## Using Formulas… for Everything—From a Complex Analysis Class to Political Cartoons to Music Album Covers

July 19, 2013 — Michael Trott, Chief Scientist

In my last blog post, I discussed how to construct closed-form trigonometric formulas for sketches of people’s faces. Using similar techniques, Wolfram|Alpha has recently added a collection of hundreds of such closed-form curves for faces, shapes, animals, logos, and signatures. In today’s post, I want to show some of the entertaining things one can do with these parametrized curves. Although these are just simple curves, a large variety of fun images (and animations) can be constructed from them. These can then be used, for example, in political cartoons, talk shows, posters, music album covers, or just to spice up an advanced calculus or first-year theoretical mechanics class. I will first discuss the fun applications, and then the more mathematical ones.

Wolfram|Alpha has hundreds of curves that can be used for the variations discussed below. Here are some example categories.

I will start by implementing two simple functions. We will work with the individual curve segments rather than with one monolithic curve, because for most of the applications below, the concrete parametrization of the whole curves does not matter. The parametrizations returned by Wolfram|Alpha are a set of truncated Fourier sums multiplied by unit step functions. The unit step functions ensure that we can use a single parametrization and nevertheless have individual disconnected line segments. The function `extractCurveSegments` gives a list of the individual curve segments that a curve is made of. And the `getSegmentLength` gives the length of a segment.

As with most Wolfram|Alpha functionality, it’s easy to import a computable form of the data into *Mathematica*. So, let’s import the parametrization of the face of Barack Obama.

We extract the individual curve segments for further use. Each curve segment is an expression in *t* that, when plotted for *t* from 0 to 2*π*, draws the visual representation of the segment.

Let us now use the segment parametrizations to build some variations of the original image. First we plot the line segments as 3D tubes of finite thickness. Although simple, this makes the curves look already a bit more interesting.

Another way to make a more interesting-looking graphic: the next graphic shows each curve segment as a spiral that originates from the segment’s center of mass.

If we sample the curve segments coarsely and position chains of disks at each curve point, we can construct some Medusa-like images. We position a disk at each point of the parametrized curve, and from each of these disks we attach a sequence of smaller and smaller disks.

And here the same is done with spheres instead of disks in 3D.

If we sample the curve segments densely, we can build a 3D plot of the distance of all points {*x*,*y*} of the plane to the nearest (or second nearest, …) curve segment points. To do so efficiently, we use `Nearest`.

The resulting image looks more interesting than the curves themselves, as we now also see some structure in the regions between the curves.

So far, we have kept the curve points and placed and added various additions to the plot. We can also change the actual coordinates of the curve points. Having the coordinates of the curve points in explicit form at hand, we can easily take the square root of the curves. The next graphic shows the resulting curves for taking the square root in *x*,*y* coordinates and in polar coordinates.

Generalizing the map to arbitrary power functions is straightforward, and the following interactive example allows arbitrary reference points and exponents. For some more visual variety, we use some current and former presidents and prime ministers. In addition to the power function mapping parameters, we allow the interactive change of the coordinate system origin through a locator.

Now let’s switch to another person curve. This is a sketch of Wolfram|Alpha’s creator, Stephen Wolfram.

We again extract the individual curve segments for further use.

We plot again the distances of points in the plane to the nearest line segment. The middle and right image show the distances to the second-nearest and the third-nearest curve segments. Not unexpectedly, measuring the distance to more distant line segments loses important facial structures.

Here are two more uses of the distance array; this time, we make three array plots from the data that was used to make the last plot.

Here is a version of Stephen in a Roman mosaic fresco style. To construct it, we start with a semi-random array of points. For these points we build a Voronoi diagram of these points (using `ListContourPlot[points, InterpolationOrder->0]`). We map the individual polygons of the Voronoi diagram into 3D (to get a more realistic mosaic feeling) and color them according to the distance to the points of the curve segments.

And here is a more modern art version of Stephen Wolfram. On a square grid, we imprint the curve segments as if they act gravitationally on the grid vertices and slightly deform the grid.

Since the sketch of Stephen Wolfram’s face is given as a set of curves, we can apply various differential geometric operations. The next graphic shows the pedal curve and the contrapedal curve of the face curves, meaning that the curves are defined in such a way that a point on the new curve is perpendicular to the tangent (normal) of the original curve with respect to a point *P* (the locator). (Initially, we put the pedal point in Stephen’s left nostril.)

Rotating the curves that form the face outline around the *z* axis gives an interesting-looking 3D image of Stephen Wolfram’s face.

Now let’s take the last two face curves, the ones from Wolf Blitzer and Anderson Cooper, and morph them into each other. Because the parametrizations don’t allow a one-to-one map, we can’t directly interpolate between the parametrized curves, but we can easily interpolate between the points of the curves. First we rescale the curves, so that the two faces are identically positioned and scaled.

We select 20,000 points on each face curve set and find the nearest point on the other face curve set. Then we interpolate between these point pairs.

These are the lines of interpolation between the point pairs.

Using the just-calculated transition and boundary points, we can quickly generate relief plots of their faces.

And here again is a transition between the two faces.

The following interactive version allows us to change the transition parameter and connects the resulting interpolating point set.

Or we could use a drawing of Jay Leno.

Here is again the nearest curve segment plot of its defining line segments.

Here are two modified interactive “line drawings” of Jay. In the first graphic, the line numbers, line lengths, and line angles can be changed interactively.

We can also braid tubes along our curve segments. Or depict a more prickly Leno made from thousands of little arrows.

And here is his portrait rotated in 3D along a snail-shell-like curve.

We continue with some variations of Lady Gaga.

She surely would not want to be displayed as a uniform thin, plain blue curve. So, let’s broaden and color the line segments.

The next graphic is made with 50,000 randomly placed and colored *n*gons. The size and the opacity of the *n*gons are a function of the distance to the nearest point of one of the curves that make the face sketch.

And here are two calls to `ListContourPlot` with the points of Lady Gaga’s curves. We select the points for the plot randomly from a rectangular array of points according to distance-dependent probability distributions. The right image we color according to her infamous meat dress.

Using the polygons from the left graphic and round corners, we obtain the following pebble-stone-like images.

Two more variations on Lady Gaga—cones and cylinders randomly placed along the defining curves embedded in 3D.

Next, we import the image of a feather.

By randomly re-coloring this feather, we can place colored feathers along line segments of the curve. The sizes of the feathers are determined by the size of the original curve segment.

We can make similar images for other curves, not just for people, and also for fictional characters (for example, for Tinky Winky).

Here is a 3D picture of Tinky Winky.

And in the next image, we carry out an inversion on Tinky Winky.

Or we could use Miss Piggy.

And we can use the points from less densely sampled segments to make a Voronoi tessellation of the data.

Let’s contract Miss Piggy’s curves recursively.

And the next image interpolates between the curve points and the curve points mapped to the nearest point on a larger, all-enclosing circle.

Next, we will charge (electrically) Miss Piggy and calculate the resulting electric field from the charged discretized curve segments. Here is the electric field of a charged line segment.

These are the lines of equal field-strength magnitude.

Or, we can make use of a parametrization of Dilbert.

Here is Dilbert with spheres of radii that are proportional to the distance to the nearest curve points. The left graphic uses randomly placed spheres and the right graphic uses spheres with centers on a square grid.

Having a Dilbert curve at hand, what would be more natural than to unite it with a Hilbert curve, the well-known space-filling curve?

We imprint the Dilbert curve into the Hilbert curve by elevating the points near to the Dilbert curve.

And here is a logo curve transformed (pun intended) into a 3D plot.

There are many more real and fictional celebrities that we could sketch and modify. Here are three. We encode their names. Do you recognize them? Click here for the spoiler.

And here is a fictional character. Again, click for the spoiler.

Instead of drawing the curves, we draw many (about twenty-five thousand) osculating circles at points from the defining curves to obtain a natural bubble environment.

Yet another possible curve usage is the making of coloring pages. The next input implements the mapping of a randomly selected Pokémon figure into a polygon.

And here is a possible arrangement of Pokémon characters to be colored.

Some apply some unconventional coloring.

We’ve had our fun with people and fictional characters. But before having more fun with them in animations, let’s do some more mathematics related to curves. For example, we could use the curves to do a bit of complex analysis. Let’s start with a curve that approximates the letter *π*.

In the next graphic, we map the plane into the complex plane and plot the argument of the modular function inverse elliptic nome. The dense set of singularities on the natural boundary of analyticity of the inverse elliptic nome gives the intricate fine structure that we see along the outline of *π*.

Next, we form a rational function in *z* based on the Fourier series.

The rational function evaluated at *z* = exp(*i* *φ*) traces out the letter *π*. For *z* = *R* exp(*i* *φ*), we obtain different-looking curves. Similarly, rational functions and, after normalization, even polynomials could be used for people curves, shape curves… So, if we need polynomials for some curve applications, we can always construct them from the trigonometric sine sums.

In the next graphic we form a polynomial of degree 128 with simple roots along the outline of *π*.

Here is a plot of the curves of constant real and imaginary parts of the last polynomial.

Let’s carry out another complex analysis example. We know that with a conformal map, we can map any nice, single-connected region of the complex plane to the unit disk. And in many instances, a series approximation of the conformal map will give good results. For instance, here is the exact map that maps a square to a disk. It’s a bit complicated and contains Jacobi elliptic functions.

The series approximation is quite simple.

And visually, the series with only the two leading terms already gives a reasonable approximation of the map.

So, let us to try to find complex maps that map person A into person B. Because we cannot independently map the exterior boundaries and interior features, the mapping will definitely not be perfect. But watching the algorithm that tries to minimize the difference between person A and person B carrying out the conformal map on person A or B is entertaining at least. So we implement the finding of such a conformal map. Here are eight pairs of persons to be mapped.

Let’s solve some partial differential equation calculations with the Newton curves to honor the co-inventor of differentiation. In preparation, let’s consider the 2D Fourier series of the curves that define Newton’s face, which we constructed in the last blog post.

We will rescale the curves to fit into [0,1] X [0,1] and use the (unnormalized) 2D Fourier basis functions *ψ** _{k}*,

*= sin(*

_{m}*k*

*π*

*x*) sin(

*m*

*π*

*y*). Effectively, we want to approximate a Dirac delta function along the defining curves and the zero function anywhere else.

We calculate the 2D Fourier coefficients using numerical integration. We will calculate quite a few coefficients, namely 200^{2}.

To assemble the Fourier approximations, we use a tensor product grid in the *x*,*y* plane for efficiency. The function `xyArray` takes an optional argument “`FourierCoefficientMultiplicator`” -> * value* that we will use in a moment.

This is the resulting Fourier approximation of the 2D curves shown in 3D.

The next plot shows how the (scaled) function values increase with an increasing number of Fourier modes taken into account. We see that we need many more Fourier coefficients for a good-looking image than we needed Fourier modes for the curves themselves.

Remembering the separation of variables method to solve partial differential equations, we can use the Fourier coefficients to straightforwardly obtain the time-dependent solutions of the wave equation and the heat equation. The above shown Fourier expansion is the initial conditions at *t*=0.

Here is the time-evolved version of Newton’s face under the wave equation. (We assume vanishing initial velocities everywhere.)

And here is the time-evolved version of Newton’s face under the heat equation–it seems most suited for Halloween.

And if Newton’s face were a microparticle and would obey the Schrödinger equation, then quickly the localized face would flow apart and after a short time would look so:

We now end our advanced calculus applications of the curves.

With a bit more effort, we can try to animate some of the curves instead of just constructing static images. For instance, we could take three closed curves and morph them. This is done here using a pig, a unicorn, and a yeti silhouette.

We first normalize the curve in size and then form the superposition chimera *c*_{pig} *curve** _{pig}* +

*c*

_{unicorn}*curve*

*+*

_{unicorn}*c*

_{yeti}*curve*

*.*

_{yeti}

Above we had fun with people’s faces; we used some curves to solve partial differential equations, so let’s now do some physics, especially mechanics.

Assuming a flexible Barack Obama, we could model the defining curves as discretized elastic springs with harmonic nearest neighbor forces. We also assume a coupling from the end of each line segment to the beginning of the next line segment (the complex-valued connections in the parametrizations). The resulting mechanical system is described by Newton’s equation of motion *m* * X*“(

*t*)=

*(*

**F***(*

**X***t*)), where

*(*

**X***t*) is the vector of the positions of all the points on the curve segments. Of special interest for a mechanics class are the eigenmodes of the resulting mechanical system, generalizing the eigenmodes of the linear chain.

Or we can get a bit crazier with the animations: let’s marry two curves (each in its 2D plane) in 4D. First we select two shapes, say *π* and the hammer and sickle symbol.

Then we form a two-dimensional surface in a four-dimensional space. The four coordinates of the surface are {*c*_{π,x}(*s*),*c*_{π,y}(*s*), *c* _{hs,x}(*t*), *c*_{hs,y}(*t*)}, where {*c*_{π,x}(*s*), *c*_{π,y}(*s*)} is the parametrization of the pi curve and {*c*_{ hs,x}(*t*), *c*_{hs,y}(*t*)} is the parametrization of the hammer and sickle curve. We then look at this surface by projecting it into a three-dimensional subspace specified by rotations in the four-dimensional space.

We could do something similar with two faces and amalgamate them into a Janus-type 4D object. The resulting surface will look quite intricate, and we encourage the reader to find some appropriate pairs of people to unite in higher dimensions.

We end today’s blog post with a curve that is nearly begging to be animated: Psy’s dance.

We do not go to great length with character animations here. Instead, we just rotate parts of his arms and legs at the elbow and knee joints. To achieve a more realistic Gangnam dance animation, we would have to add rotations around the hip.

In the next blog post in this series, we will look at laminae, meaning curves together with their insides. For their constructions, quite different mathematical techniques will be used.

To interact with the examples above, first, download the Wolfram *CDF Player*. Then, download this post as a Computable Document Format (CDF) file.

## 6 Comments

Great blog post!

Phantastic!

Impressive show of possibilities how using formulas.

Michael, do you think is posible given the closed formula let’s say for Obama’ Face simulate the effect of the rotation of the face? Like in 3D rotation? That may be useful for creating 2D animation.

Terrific! Can you help President Obama do the gangnam dance?

Awesome!