[an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] Skip to the content of the web site.

Fractals

Fatou-Julia Sets

Given a number c, another point z0 is in the Fatou-Julia set of c if the sequence

zn + 1 = zn2 + c
remains bounded. If |zn| > 2 for any n, then then the sequence |zn| → ∞.

The following program uses the C++ Quaternion class to test various points for membership in the Fatou-Julia set for a given c. It is by no means an efficient means of calculating a Fatou-Julia set.

#include "Quaternion.h"
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    const int N = 100;
    const int M = 10;
    double delta = 2.0 / M;

    Quaternion<> c( -0.63543, 0.172645, 0.172645, 0.0 );

    for ( int r = -M; r <= M; ++r ) {
        for ( int i = -M; i <= M; ++i ) {
            for ( int j = -M; j <= M; ++j ) {
                Quaternion<> z0( delta*r, delta*i, delta*j, 0 );
                Quaternion<> z = z0;

                int n;

                for ( n = 0; n < N; ++n ) {
                    z = sqr(z) + c;

                    if ( z.norm() > 4 ) {
                        break;
                    }
                }

                if ( n == N ) {
                    cout << "(" << z0.real()   << ","
                               << z0.imag_i() << ","
                               << z0.imag_j() << ")" << endl;
                }
            }
        }
    }

    return 0;
}

Mandelbrot Set

The number z0 is in the Mandelbrot set if 0 is in the Fatou-Julia set of z0, that is, the sequence

zn + 1 = zn2 + z0
remains bounded. If |zn| > 2 for any n, then then the sequence |zn| → ∞.

The following program uses the Quaternion class to test various points for membership in the Mandelbrot set. It is by no means an efficient means of calculating the Mandelbrot set.

#include "Quaternion.h"
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    const int N = 100;
    const int M = 10;
    double delta = 2.0 / M;

    for ( int r = -M; r <= M; ++r ) {
        for ( int i = -M; i <= M; ++i ) {
            for ( int j = -M; j <= M; ++j ) {
                Quaternion<> z0( delta*r, delta*i, delta*j, 0 );
                Quaternion<> z = z0;

                int n;

                for ( n = 0; n < N; ++n ) {
                    z = sqr(z) + z0;

                    if ( z.norm() > 4 ) {
                        break;
                    }
                }

                if ( n == N ) {
                    cout << "(" << z0.real()   << ","
                                << z0.imag_i() << ","
                                << z0.imag_j() << ")" << endl;
                }
            }
        }
    }

    return 0;
}