How To Draw Einstein's Face Parametrically
Written by Mike James   
Thursday, 19 July 2018
Article Index
How To Draw Einstein's Face Parametrically
Fourier Transform
Mathematica Makes It Easy
A Feat in Python

There are some amazing math artworks on Wolfram Alpha. I was captivated by parametric equations that draw the faces of well known people and all using a few Sin functions. How is this achieved? It seems like a lot of work to go to if the curves are constructed by manual trial and error. The good news is that they are not - we show you how using Wolfram and Python.

First we need to look at what people have produced. If you go to Wolfram Alpha and search for "person curve" you will discover that are more than 140 examples of these mathematical portraits. A popular and fairly typical one is of Albert Einstein:

 

einstein

 

What you are looking at is an x, y plot of a pair of functions. If you look at the Equations window below the plot you will see that these are no simple functions:

curve

 

Someone spent days or months handcrafting equations that produce the portraits in mathematical form - or did they? If you are going to produce a mathematical equation then presumably you know some math and math can always help you eliminate tedious work - unless, that is, you are still at the stage of confusing math with arithmetic. 

There is a mathematical procedure for producing these equations and it isn't that difficult, even though it does involve some reasonably advanced ideas.  

Let's find out how it all works by way of first a simple illustration using Mathematica and then an equivalent Python program. 

Parametric equations

First what is a parametric equation?

Standard graphs simply plot one value of y for each value of x and clearly this is not what is happening here. To create graphs that have multiple values of y for each value of x you have to do things slightly differently and this is where parametric functions come in. 

A pair of parametric functions give you a value fo x and a value of y for each value of their parameter. That is

x=f(t) and y=g(t)

To create a plot all you have to do is take different values of t and plot the resulting x and y values. 

For example in Mathematica you can write:

f[t_] := Sin[t]
g[t_] := Cos[t]
ParametricPlot[{f[t], g[t]}, {t, 0, 2*Pi}]

And a plot will be drawn of all the x,y pairs for t from 0 to 2*Pi and the result is a circle (allowing for distortion due to the aspect ratio):

 

parametricplot

 

You can create the same plot in Python as long as you have MatPlotLib, Numpy and/or SciPy installed.  

import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0,2*np.pi, 0.1);
plt.plot(np.sin(t), np.cos(t))
plt.show()

  pythoncircle

 

If you vary the mix of trigonometric functions you can create closed curves with complicated shapes.  

For example:

 

complexcurve

 

So our problem now is to work out a combination of Sin functions of different amplitudes and frequencies to change the complex but messy curve above into something that looks like Einstein. 

This is not going to be easy.

First, digitize your curve

No doubt if you spend a lot of time on the problem you will eventually pick up some intuitions into how to create shapes of particular types. Eventually you could put together a toolkit of shapes that you could use to make other shapes - but this doesn't sound like a good way to spend your creative talent. 

The easy way to do the job is to start of with a digitization of the curve you want to create. You can obtain this by manually measuring a photo using Photoshop or Gimp or you could use a filter that automatically converts the grey scale photo to a line drawing. Alternatively if you really do have some artistic talent you could actually sketch the line drawing you want to turn into a parametric curve. 

As I don't have any talent, I'm going to use a crude digitization of an eye shape to show you how things work. I'm also not going to cover how to use or create a line filter. 

x=[0,1,4,6,8,10,8,6,4,1,0]
y=[0,2,3,3,2,0,-2,-3,-3,-2,0]
plt.plot(x, y)
plt.show()

 

eye



Last Updated ( Friday, 20 July 2018 )