Fractals/Iterations in the complex plane/demj

This algorithm has 2 versions:
 * exterior
 * interior

Compare it with version for parameter plane and Mandelbrot set : DEM/M =External distance estimation=

Distance Estimation Method for Julia set ( DEM/J ) estimates distance from point z ( in the exterior of Julia set ) to nearest point in Julia set.

For distance estimate it has been proved that the computed value differs from the true distance at most by a factor of 4:

Koebe Quarter Theorem. The image of an injective analytic function f : D → C from the unit disk D onto a subset of the complex plane contains the disk whose center is f(0) and whose radius is |f′(0)|/4.

Math formula :

$$distance(z_0, K_c, n) = 2 * |z_n| * \frac{\log|z_n| }{ |z'_n| }\,$$ where :

$$z'_n\,$$ is first derivative with respect to z.

This derivative can be found by iteration starting with


 * $$z'_0 = 1 \,$$

and then :

$$z'_n= 2*z_{n-1}*z'_{n-1}\,$$

Pseudocode and the code

 * The Beauty of Fractals
 * The Science of Fractal Images, page 198,
 * Distance Estimator  by Robert P. Munafo

Pseudocode by 	Claude Heiland-Allen foreach pixel c while not escaped and iteration limit not reached dz := 2 * z * dz + 1 z := z^2 + c de := 2 * |z| * log(|z|) / |dz| d := de / pixel_spacing plot_grey(tanh(d))

tanh
double g = tanh(distance / PixelWidth); return 255*g; // iColorOfExterior;

distance max
Distance max is the old ( deprecated) method.

One can use distance for colouring :
 * only Julia set ( boundary of filled Julia set)
 * boundary and exterior of filled Julia set.

Here is first example :

Here is second example

distance max
Distance max is the old ( deprecated) method.

DistanceMax is smaller than pixel size. During zooming pixel size is decreasing and DistanceMax should also be decreased to obtain good picture. It can be made by using formula :

$$DistanceMax = \frac{PixelSize}{n} \,$$

where $$n \le 1 \,$$

One can start with n=1 and increase n if picture is not good. Check also iMax !!

DistanceMax may also be proportional to zoom factor $$mag\,$$:

$$DistanceMax = \sqrt{\frac {thick}{1000 * mag}}$$

where thick is image width ( in world units) and mag is a zoom factor.

One can use also tanh which gives more precise look:

distance = 2.0 * cabsz* log(cabsz)/ cabs(dz); double g = tanh(distance /PixelWidth); return 255*g; // iColorOfExterior;

Examples of code
For cpp example see mndlbrot::dist from  mndlbrot.cpp in src code of program mandel ver 5.3 by Wolf Jung.

C function using complex type :

C function using double type:

Delphi function :

Matlab code by Jonas Lundgren

Maxima function :

shadertoy

 * Julia - Distance 1 by iq. Analytical distance to a Julia set z^2 + c where vec2 c = vec2( -0.745, 0.186 )
 * Julia - Distance 2 by iq = SDF for the Julia set of f(z) = z^3+C where const vec2  kC = vec2(0.105,0.7905);
 * Julia - Distance 3 by iq. A generic Julia set renderer, using distance to the set (Douady_Hubbard potential). In this case I'm using a rational function of order 6: f(z) = (z-(1+i)/10)(z-i)(z-1)^4 / ((z+1)(z-(1+i)) + c
 * Inigo Quilez  ::   articles   ::   distance to fractals - 2004

=Internal distance estimation=

Colouring the Julia set by Gert Buschmann
In order to get a nice picture, we must also colour the Julia set, since otherwise the Julia set is only visible through the colouring of the Fatou domains, and this colouring changes vigorously near the Julia set, giving a muddy look (it is possible to avoid this by choosing the colour scale and the density carefully). A point z belongs to the Julia set if the iteration does not stop, that is, if we have reached the chosen maximum number of iterations, M. But as the Julia set is infinitely thin, and as we only perform calculations for regularly situated points, in practice we cannot colour the Julia set in this way. But happily there exists a formula that (up to a constant factor) estimates the distance from the points z outside the Julia set to the Julia set. This formula is associated to a Fatou domain, and the number given by the formula is the more correct the closer we come to the Julia set, so that the deviation is without significance.

The distance function is the function $$\delta(z) = \phi(z)/|\phi'(z)|$$ (see the section Julia and Mandelbrot sets for non-complex functions), whose equipotential lines must lie approximately regularly. In the formula appears the derivative $$z'_k$$ of $$z_k$$ with respect to z. But as $$z_k = f(f(...f(z)))$$ (the k-fold composition), $$z'_k$$ is the product of the numbers $$f'(z_i)$$ (i = 0, 1, ..., k-1), and this sequence can be calculated recursively by $$z'_{k+1} = f'(z_k)z'_k$$ and $$z'_0 = 1$$ (before the calculation of the next iteration $$z_{k+1} = f(z_k)$$). In the three cases we have:


 * $$\delta(z) = $$limk→∞$$|z_{kr} - z*|/|z'_{kr}|$$ (non-super-attraction)
 * $$\delta(z) = $$limk→∞$$log|z_{kr} - z*||z_{kr} - z*|/|z'_{kr}|$$ (super-attraction)
 * $$\delta(z) = $$limk→∞$$log|z_k||z_k|/|z'_k|$$ (d ≥ 2 and z* = ∞)

If this number (calculated for the last iteration number kr - to be divided by r) is smaller that a given small number, we colour the point z dark-blue, for instance.

For more see Pictures_of_Julia_and_Mandelbrot_Sets

code
=references=
 * Explicit estimates on distance estimator method for Julia sets of polynomials by Masayo Fujimura, Yasuhiro Gotoh, S. Yoshida Published 1 October 2013
 * Distance Estimator algorithm by E Demidov
 * math.stackexchange question: interior-distance-estimate-for-julia-sets-getting-rid-of-spots