How to Draw Almost Anything

When learning about mathematical functions in high school, one of the most fun exercises I remember was plotting them on graph paper.

The process is simple:

  1. Take a function
  2. pick a value of \(x\)
  3. Calculate the value of \(y\) according to the equation
  4. place a dot in the cartesian plane with coordinates \((x, y)\)

As you keep incrementing \(x\) and placing more dots, the shape of the function slowly appears in the paper, and then it’s just a matter of joining the dots with straight lines.

Of course, if you use very few points, the curve would appear choppy. If you want a more accurate shape, you need to reduce the increments of \(x\), and have a very sharp pencil and a good pulse to draw the curve with accuracy.

Thankfully graphing calculators do all the work for you. You type in a function, and it automatically draws it on the screen. Computers are magic!

As a high school student, I wondered what function I needed to type in order to draw a circle, a spiral, a triangle, or any other thing besides straight lines and polynomials.

With time, I learned that functions have a fundamental property that makes drawing more complex shapes impossible. And once you overcome this, you can draw almost anything you want.

Functions are limited

A function can have one and only one value of \(y\) for each value of \(x\). The opposite is not true, since we can draw functions that have the same value of \(y\) at different \(x\) coordinates, such as trigonometric equations.

So in any function, if we were to slide a vertical line along it, we would find out that it only intersects in a single point. The \(y\) coordinate ultimately depends of the \(x\) coordinate. In order to have more flexibility, we need to make the \(x\) and \(y\) coordinates independent of each other.

Parametric functions to the rescue

Parametric functions let us control the \(x\) and \(y\) coordinates with a third parameter, \(t\). Think of it as a progress indicator that tells you how far along you are in the drawing.

A parametric function takes two functions \(x(t)\) and \(y(t)\) and combines them to create \(P(t)\), a function that returns a point in 2D space.

For example, if we use sine and cosine, we can create a circle of any size.

\[P(t) = (R \cos(t), R \sin(t))\]

If we add an offset, we can translate the circle.

\[P(t) = (R \cos(t) + O_x, R \sin(t) + O_y)\]

If the radius depends on the parameter \(t\), a spiral emerges.

\[P(t) = (t \cos(t), t \sin(t))\]

Just like manually graphics functions in paper, we calculate the coordinates for different values of \(t\) and join them using straight lines. The more points we use, the more accurate the shape will be.

Problems when drawing functions

There’s a problem when using this method to draw functions. If we use evenly spaced values of \(t\) to draw the points, it’s not guaranteed that the points will be evenly spaced too.

Take for example the parametric equation for drawing a cardioid:

The points at the bottom seem to be more spaced out than the ones at the top, even though the increments of \(t\) are constant. We end up having too many points at the top, and not enough at the bottom.

How can we solve this? Is there a method to draw a function using evenly spaced points?

Plotting speed

If we imagine a point moving along a parametric function, why not track its speed? After all we have a function that determines it’s position given time.

If we want to know the average speed of a point between times \(t_1\), \(t_2\), we can use the speed equation:

\[\text{average speed} = \frac{\text{distance traveled}}{\text{time taken}}\]

If we treat the output of a parametric function as a vector, we can calculate distances and speeds

\[\text{average speed} = \frac{|P(t_2) - P(t_1)|}{t_2 - t_1}\]

If we bring \(t_1\) and \(t_2\) very close together, we can obtain the instantaneous speed.

\[S(t) = \lim_{\Delta t \to 0} \frac{|P(t + \Delta t) - P(t)|}{\Delta t}\]