Skip to content

About

Visualizing fractals and functions of a complex variable

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

52 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This repository contains code written for my thesis project at the University of Virginia, for which I am developing a library for plotting fractals and functions of a complex variable using NVIDIA graphics cards. The code is divided across five files, each of which accomplish some "idea":

  • color.cu defines a struct for holding RGB values and some utility functions related to this representation.
  • image.cu defines a struct for images files, along with functions for reading from and writing to the .ppm format. This format stores the raw pixel values (meaning large file sizes), but is simple enough to make a reader/writer from scratch.
  • kernels.cu defines the kernels for each type of plot. This is where most of the heavy math is done.
  • stills.cu defines functions for rendering to .ppm image files.
  • window.cu defines functions for rendering in a game window.

We will now discuss each type of plot supported by the library.

Domain Coloring

Suppose we want to visualize a function $f: \mathbb{C} \to \mathbb{C}$. Because the input variable and output variable are each two-dimensional, to plot this function as we do functions $\mathbb{R} \to \mathbb{R}$ would require four spatial dimensions, a luxury we unfortunately lack.

A solution is that we can use color in our plots. The first technique we describe is known as domain coloring, wherein we draw some subset of $\mathbb{C}$ over which the function is to be plotted, and encode the output at each point in that point's color.

In particular, given a complex number $z \in \mathbb{C}$, the function

$$\begin{align*} H &= \frac{\arg z}{2\pi} + \frac{1}{2} \\ S &= 1 \\ L &= \frac{2}{\pi}\arctan|z| \end{align*}$$

defines a color in the $HSL$ color model. This will be the color we assign to the pixel corresponding to the point $z$. However, we first need to convert it from the $HSL$ color model to the $RGB$ model. This is done using the function hsl_to_rgb defined in color.cu, inspired by the procedure detailed by Saravanan, Yamuna, and Nandhini.

Heuristically, what this accomplishes is that the phase (or angle) of $f(z)$ is encoded by the hue of $z$, while the magnitude of $f(z)$ is encoded by the brightness of $z$. With domain coloring, we can produce visualizations like the following depiction of the polynomial $z^3 - 1$.

Pictorially, we can see its roots, the third roots of unity, because in our color map, a magnitude of zero corresponds to black.

Phase Portraits

Phase portraiture is a variation on domain coloring, except that the magnitude of $f(z)$ is ignored; the phase of $f(z)$ is the sole determinant of the color we assign to $z$.

Conformal Mapping

TODO Mercat

Escape-Time Fractals

TODO

Normalization

TODO

To-Do List

One major area for work is improving efficiency. This includes running experiments to measure the impact of:

  • Vectorize stores by using uchar3.
  • Use fused multiply-adds (FMA) wherever possible, such as in lerp, the kernels (indices to complex), and hsl_to_rgb (chroma, x, m).

Another area for work is code quality. This includes:

  • Unify the (three) plot-specific CUDA kernels into a single generalized kernel.
  • Make this documentation more thorough.

Finally, there are additional features we would like to support, such as:

  • Add Toggleable axes in the window.
  • Add phase portraits as another plot type.
  • Develop a CPU version that does not rely upon CUDA.

References

Many examples and techniques were drawn from these excellent resources. I highly recommend them if you are looking to learn more.

About

Visualizing fractals and functions of a complex variable

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages