Generating the Images

The source code for this project can be found at my GitHub: https://github.com/SSODelta/PolynomialVisualizer

There are many ways of visualizing numbers in the complex plane, as seen in my previous post on Newton’s Fractals. This post will detail another method of getting pretty pictures from equations.

The basic idea of this method is to visualize where each complex number is mapped to by some polynomial. The color will depend on the direction the complex number goes after having been through the polynomial, and the distance it travels. Alright, let’s get formal!

Like the post on Newton’s Fractals we start off with a polynomial of some degree. Call this $q$.

To generate a fractal, we first need to specify how large the image we need to make is, call this $[w, h]$, where $w$ is the width in pixels, and $h$ is the height (also in pixels). Next up, we have to specify which numbers we’ll use, so we decide on a resolution $r$ – we’ll only consider complex numbers $a + bi$, where $a,b \in [-r,r]$.

Now, we’ll iterate over every single pixel $p(x, y)$ in the image. Then, the associated complex number will be $C =i \cdot (\dfrac{2 \cdot r \cdot y}{h} - r) +$ $\dfrac{2 \cdot r \cdot x}{w} - r$. To make it more clear why this is the case, take a look at the real and imaginary parts individually:

• Re:  $-r + 2 \cdot r \cdot \dfrac{x}{w}$
• Im: $-r + 2 \cdot r \cdot \dfrac{y}{h}$

Anyway, we now have a complex number $C$. Now, we’ll calculate $D = q(C)$, where $q$ was the polynomial we chose. Next up, we’ll construct a vector $\vec{V} = <\mathbf{re}[C] - \mathbf{re}[D], \mathbf{im}[C] - \mathbf{im}[D]>$.

From this vector, we’ll calculate the angle between a vector pointing to the right of the screen – this is the just the $\mathbf{atan2}$ function of the vector. So, we get an angle $\theta = \mathbf{atan2}(\vec{V})$.

For the next part, we’ll start by calculating a value $\zeta$ $=$ $\dfrac{|\vec{V}|}{\sqrt{w^2 + h^2}}$, and two values $a = \sin(\zeta)$, and $b$ $=$ $\cos(\zeta)$.

We’ll treat these three values $\theta$, $a$, and $b$ as the three color components of the HSV-color type. We’ll now use the same conversion process as described in my post on psychedelic animations to convert HSV to RGB.

Then we’ll paint the pixel at $p(x, y)$ with the color information.

If we do this process for all pixels, we get impressive images:

To see an album with 78 of these images, check out my Imgur-album here: http://imgur.com/a/Ii5VM

Analyzing the images

One of the first things I noticed with these images is obviously the yellow shape in the middle of the layers of circles. What I think is interesting is that if we project the yellow pixels in the central shape over the central x-axis of the image, they don’t encounter another yellow pixel.

Said in another way, if you cut the image horizontally and overlay the two halves, the yellow pixels in the central shape don’t touch. They are disjoint, in other words.

We can also specify this (somewhat) formally. If a pixel $p(x,y)$ is yellow (and in the entral blob), then $p(x, h-y)$ won’t be yellow.

The sad thing is that I don’t have the slightest clue why this happens. If someone smarter than I knows why the images look like they do, feel free to use the comment section down below to enlighten me!

Making the images even cooler

If we have an image $I_ {pre}$ of size $[w, h]$ (the images we’ve generated), we construct a new image $I_{post}$ of size $[w, \dfrac{h}{2}]$. And for each pixel $p(x, y)$ in $I_{post}$, we paint it with color $I_{pre}(x, y)$ $\oplus$ $I_{pre}(x, h-y)$, where $I(x,y)$ represents the color information in image $I$ at position $(x,y)$.

My original idea was that this would make it evident that the yellow parts are disjoint when reflected over the central x axis, but it turns out it doesn’t.

Original Image $I_{pre}$:

Processed Image $I_{post}$:

Clearly, this does not convey much information about the central yellow  blobs, but it looks really, really cool.

Here are some more images that have been processed:

Original Image $I_{pre}$:

Processed Image $I_{post}$:

Original Image $I_{pre}$:

Processed Image $I_{post}$:

Unfortunately, I don’t have an album with lots of processed images, but if you want you can try running the code yourself.