Mandelbrot设置分形码 [英] Mandelbrot Set Fractal Code

查看:141
本文介绍了Mandelbrot设置分形码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对复杂变量使用以下Complex类文件。

I use the following Complex class file for Complex variables.

下面的java代码是Mandelbrot Set迭代计算器的一个例子。

The java code below is an example of iterations calculator for Mandelbrot Set.

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;
}

提前致谢!

推荐答案

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

I think in the function squared you need to use the absolute value:

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

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

    return new Complex(newreal, newimaginary);
}


现在,为了对一个复数进行平方,我展开了这个等式:
(Zx + Zyi)2 =
Zx×Zx + Zx×Zy + Zx×Zy - Zy×Zy =
Zx2-Zy2 + 2(Zx×Zy)
真实部分是Zx2-Zy2。将它们相乘(Zx Zx部分)比使用函数将数字增加到另一个更快更快。
虚部是2(Zx×Zy)。设置变量n = Zx
Zy然后设置n = n + n以避免乘以2(加法比乘法更快)更快。 Zy是一个浮点数,所以我不能做一点左移乘以2。
现在与Mandelbrot集不同的部分是:
Zy = Math.abs(Zx * Zy);

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

这篇关于Mandelbrot设置分形码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆