【问题标题】:Mandelbrot Set Fractal CodeMandelbrot 集分形码
【发布时间】:2015-03-02 17:15:55
【问题描述】:

我将以下复杂类文件用于复杂变量。

下面的 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;
}

提前致谢!

【问题讨论】:

  • 维基百科页面上的功能有什么不清楚的地方?

标签: java fractals


【解决方案1】:

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

 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。将它们相乘(ZxZx 部分)比使用函数将数字提升到另一个更快。 虚部是 2(Zx×Zy)。设置一个变量 n = ZxZy 然后设置 n = n + n 以避免乘以 2 更快(加法比乘法更快)。 Zy 是一个浮点数,所以我不能左移一位来乘以 2。 现在与 Mandelbrot 集不同的部分是: Zy=Math.abs(Zx*Zy);

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

【讨论】:

    猜你喜欢
    • 2012-12-15
    • 1970-01-01
    • 2013-04-13
    • 1970-01-01
    • 1970-01-01
    • 2012-12-11
    • 2013-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多