Phase Plots of Complex Functions

The concept here is quite simple: visualize the values of a complex function by mapping them to colour, using multiple dimensions of colour space to capture the two dimensional result.

It is useful to use the polar coordinate representation here and use the modulus or magnitude of the polar coordinate vector and the phase angle or angle of the polar coordinate vector to drive the colour choice. Zeros of the complex function will then naturally map to wells of colour.

A complex number z = x + yi = r e = r(cos(φ) + i sin(φ)) has a modulus of r = √(x² + y²) and an angle of φ = atan2(y, x).

Many colour schemes are possible. See [1] for some examples and discussion. Typically the angle is mapped to hue and the modulus is mapped to brightness in some fashion. Linear or logarithmic mappings can be used. Since human colour perception is not uniform, naive mappings can create artificial perceptual discontinuities. These may produce beautiful results, but they can be misleading. For example, here is figure 1 from [1]. The colour banding such as between yellow and red here is an artifact of the colouring.

My approach is to map the hue onto a perceptually uniform and ordered gradients, such as those in [2]. Compare the dark banding in the first gradient below to the smoothness of the second.

The gradient's colours are converted into HSL colour space, then the angle of the function is used to select the appropriate colour. I use the hue and saturation values as is and blend the lightness value with a value mapped from modulus. So: function values get darker as they approach zero and span the colour range as they rotate.

Linear gradients will produce a strong discontinuity at 360°. Circular gradients will smooth this out. Compare these two plots of complex modulated torus knots. The first one uses a linear gradient and shows the discontinuities. The second uses a circularized version of that gradient and is smooth: the remaining colour discontinuities reflect properties of the underlying function.

Uninterpolated gradients with few colours will also also produce strong discontinuities, at the angles corresponding to the number of colours. This image uses a gradient with only five colours, so the discontinuities are every 72 degrees. Interpolating the gradient to produce more base colour values can smooth this out.

Similarly when a split gradient is used. This image uses a gradient designed for topographic uses with a strong discontinuity in the middle (where the land meets the sea). We therefore see two discontinuities: one at the end of the gradient (360°) and one where the two subgradients meet (180°).

The final pieces of the puzzle are the selection of the complex function to map and the calculation of that function (i.e. mathematical operations over complex functions). Let's take the second part first.

Wikipedia's article on complex numbers has some information on how to compute some operations; a nice summary as well as information on trigonometric functions is at the Milefoot mathematics page.

For complex numbers z = a + bi = r(cos(φ) + i sin(φ)) and w = c + di = s(cos(θ) + i sin(θ)), some basic operations are given in the table below. These are sufficient to implement many interesting complex functions.

Modulus|a + bi|r = √(a² + b²)
Phase anglephase(a + bi)φ = atan2(b, a)
Conjugateconj(a + bi)a - bi
Reciprocal1 / (a + bi)(a - bi)/r
Addition(a + bi) + (c + di)(a + b) + (c + d)i
Subtraction(a + bi) - (c + di)(a - b) + (c - d)i
Multiplication(a + bi) * (c + di)(ac - bd) + (ad - bc)i
Division(a + bi) / (c + di)((ac + bd) + (bc - ad)i)/(c² + d²)
Integral power(a + bi)nrn(cos(nφ) + isin(nφ))
Natural logln(a + bi)ln(r) + φ i
Principal square root√(a + bi)√((r + a)/2) + i sign(b)√((r - a)/2)
Cube rootscbrt(a + bi)cbrt(r) (cos((φ + 2kπ)/3) + i sin((φ + 2kπ)/3)) for k=0,1,2
Sinesin(a + bi)sin(a) cosh(b) + i cos(a) sinh(b)
Cosinecos(a + bi)cos(a) cosh(b) + i sin(a) sinh(b)

As far as which function to plot, for artistic purposes a function with a lot of zeros and a complicated surface make for more interesting results. The modulated torus knots (above) are, let us be honest, a little boring. Dividing one polynomial function by another often produces interesting results. One class of functions that reliably produces nice images is finite Blashcke products.

Given a set of points wn in the unit disk and a complex constant k with |k|=1, then the product B(z) = k Π((|w|/w) (w - z)/(1 - conj(w)z) will have zeros at the wn. By randomly selecting k and the wn a variety of pleasing diagrams can be created. Here is a phase diagram for a random 17 factor Blashcke product.