How To Draw Einstein's Face Parametrically
Written by Mike James   
Wednesday, 10 April 2013
Article Index
How To Draw Einstein's Face Parametrically
Initial Steps
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.

 

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.



Last Updated ( Wednesday, 10 April 2013 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.