Mandelbrot 集分形代码

Mandelbrot Set Fractal Code

我使用以下 Complex class 文件作为 Complex 变量。

下面的 java 代码是 Mandelbrot 集合的迭代计算器示例。

public int iterations(Complex no) {
    Complex z = no;
    int iterations = 0;
    while (z.modulusSquared() < 4 && iter <= MAX_ITERATIONS) {
        z = z.square();
        z = z.add(y);
        iter++;
    }
    return iter;
}

提前致谢!

我认为在平方函数中你需要使用绝对值:

 public Complex square() {
    double newreal;
    double newimaginary;

    newreal = ((real * real) - (imaginary * imaginary));
    newimaginary = 2 * abs(imaginary * real);

    return new Complex(newreal, newimaginary);
}

Now, to square a complex number, I expand this equation: (Zx + Zyi)2 = Zx × Zx + Zx × Zy +Zx × Zy - Zy×Zy = Zx2-Zy2 + 2(Zx×Zy) The real part is Zx2-Zy2. It is quicker to multiply them together (the ZxZx part) than use a function for raising a number to another. The imaginary part is 2(Zx×Zy). It is quicker to set a variable n = ZxZy then set n = n + n to avoid multiplying by two (adding is quicker than multiplying). Zy is a floating point number so I cannot do a bit shift left to multiply by two. Now the part that is different to the Mandelbrot set is this: Zy=Math.abs(Zx*Zy);

[¹]http://spanishplus.tripod.com/maths/FractalBurningShip.htm