计算mandelbrot集迭代有麻烦 [英] Having trouble calculating mandelbrot set iterations

查看:193
本文介绍了计算mandelbrot集迭代有麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我阅读了这篇文章: http://www.wikihow .com/Plot-the-Mandelbrot-Set-by-Hand 但是我陷入了第7步.我正在用javascript画布绘制集合.

So I read up this article: http://www.wikihow.com/Plot-the-Mandelbrot-Set-By-Hand But I'm stuck at step 7. I'm drawing the set in javascript canvas.

我需要的基本上是我猜得到的C值.

All I need is basicly the C value I guess.

for (var y = 0; y < ImageHeight; y++) {
    for (var x = 0; x < ImageWidth; x++) {

        // Pixel-Position for ImageObject
        var xy = (x + y * image.width) * 4;

        // Convert Image-Dimension to a radius of 2
        var xi = ((x / ImageWidth) * 4) - 2;
        var yi = ((y / ImageHeight) * 4) - 2;

        for (var n = 0; n < MaxIterations; n++) {

            // Complex number stuff..?
            z = (xi*xi) + (yi*yi) + c;
            c = 0; // Somethig with z ..?

            if (z < 4) {

                image.data[xy] = inner_color[0];
                image.data[xy+1] = inner_color[1];
                image.data[xy+2] = inner_color[2];
                image.data[xy+3] = Math.round(n * cdiff);

            } else {

                image.data[xy] = outer_color[0];
                image.data[xy+1] = outer_color[1];
                image.data[xy+2] = outer_color[2];
                image.data[xy+3] = Math.round(n * cdiff);

                break;
            }
        }
    }
}

我也阅读了很多有关虚数和虚数的知识,但是我不太了解如何用虚数和虚数进行计算.而且它们对我来说似乎毫无用处,因为您必须将它们转换为实数才能进行例如javascript的逻辑运算.

I also read up a lot about imaginary numbers and stuff, but I didn't quite understood how to calculate with them. And they seem somehow useless to me because you'd have to convert them back to real numbers anyways to do logic operations in javascript for example.

这是它的样子:[已删除]
如果您在网址末尾删除2,则会看到另一个版本,其中我只是重写了一些c ++代码段. 但是缩放有点奇怪,这就是为什么我要自己编写所有内容.

Here is what it looks like: [removed]
If you remove the 2 at the end of the url, you see another version where I just rewrote a little c++ snippit. But zooming is somehow weird, which is why I want to write it all on my own..

我理解了mandelbrot集创建的基本概念,但是正如我所说的那样,复杂的部分使我感到困扰.那里可能还有一个更简单的解释吗?

I understood the basic concept of the mandelbrot set creation but as I said the complex part is troubling me. Is there maybe an even simpler explanation out there ?

推荐答案

您必须先了解这一点:

z = z^2 + c

让我们分解一下.

zc都是复数(并且最近的一个问题告诉我要强调这一点,它们具有小数位,并且看起来像这样:c=-0.70176-0.3842i).复数可以包含不是实数"的部分,适当的术语是虚数部分,然后您以以下形式编写复数:

Both z and c are complex numbers (and a recent question taught me to emphasize this, they have fractional digits, and can look like this: c=-0.70176-0.3842i). Complex numbers can have a part that is 'not real', the proper term is imaginary part, and you write a single complex number in the form:

(a + bi)(a + b*i)

如果b为0,那么您有一个a + 0i,它只是a,因此如果没有虚构部分,您将拥有一个实数.

If b is 0, then you have a a + 0i which is simply a so without an imaginary part you have a real number.

您的链接未提及复数的最重要属性,尤其是其虚构部分的属性i == sqrt(-1).在实数字段中,没有负数的平方根这样的东西,这是复数出现的地方,并且您可以使平方根为-1.让我们将i提升为2的幂:i^2 == -1,魔术!

Your link does not mention the most important property of a complex number, especially a property of its imaginary part that i == sqrt(-1). On the field of Real numbers there is no such thing as a square root of a negative number and that's where complex numbers come in and allow you to have the square root of -1. Let's raise i to the power of 2: i^2 == -1, magick!

虚部(i)必须由您处理(特殊的平方),或者您使用的编程语言将提供复杂的类型来为您处理.

The imaginary part (i) has to be either handled by you (the special square-ing) or the programming language you work with will offer a Complex type which handles it for you.

现在回到扩展z^2:

z == (a+bi),因此是z^2 == (a+bi)^2,所以是z^2 == (a^2 + bi^2 + 2*a*bi).

z == (a+bi), therefore z^2 == (a+bi)^2 so z^2 == (a^2 + bi^2 + 2*a*bi).

我们也将其分解:

  • a^2 =>这很简单,它是一个实数
  • bi^2 =>棘手的部分.这确实是b^2*i^2.我们在这里得到了i^2,它是-1,这使其成为b^2*-1或:-b^2.因此,这也是一个真实数字.
  • 2*a*b*i =>这将是虚构部分
  • a^2 => this is simple, it is a real number
  • bi^2 => The tricky part. This is really b^2*i^2. And we got here an i^2, which is -1 and that makes it b^2*-1 or : -b^2. So this is also a real number.
  • 2*a*b*i => this will be the imaginary part

结果:z^2 = (a^2-b^2+2*a*bi)

示例(有点儿过分详细.您可以将其视为循环中的第一个迭代):

Example (a bit over-detailed. You can think of it as the first iteration in your loop):

z = (5 + 3i)
z^2 = (5 + 3i)^2
    = (5^2 + 3^2*i^2 + 2*5*3i)
    = (25 + 9i^2 + 30i)
    = (25 + 9*-1 + 30i)
    = (25 - 9 + 30i)
    = (16 + 30i)


现在,如果您了解复数的迭代和乘法,则可以在Mandelbrot(以及c值)上找到一些单词:


Now if you understand the iteration and the multiplication of complex numbers, some words on Mandelbrot (and on the c value):

当您要创建Mandelbrot集时,您实际上是在复杂平面上寻找点,如果使用上述迭代进行了多次迭代(例如50次),则该点永远不会达到无穷大. Mandelbrot集是通常看到的"Mandelbrot"图片的黑色部分,而不是发亮的彩色部分.

When you want to create a Mandelbrot set, you are really looking for points on the complex plane, that never goes to infinity if iterated over - say 50 times - with the iteration discussed above. The Mandelbrot set is the black part of the usually seen "Mandelbrot" pictures and not the shiny, colored part.

通常的工作流程是这样:

The usual workflow is this:

  • 在复平面上选择一个点,例如(1.01312 + 0.8324i)=>这将是c的值!
  • 在第一次迭代之前,将(0,0i)放入z中,然后迭代多次,如之前=> z = z^2 + c所述.是的,您要对一个点进行平方并添加相同的点,这是 Mandelbrot集的非常重要的属性.对于初学者,请执行此操作50次.这样会给您一个复杂的数字.
  • 如果所得复数的任何部分(实数或虚数)等于或大于2,则我们假定此点将变为无穷大,并且认为该点不存在 Mandelbrot集的一部分*.需要为点着色时就是这种情况(这是Mandelbrot集的彩色部分).如果复数的两个部分都小于2,则假定该点永远不会达到无穷大(即使迭代了数十亿次),并将该点视为Mandelbrot集的一部分,其颜色将为黑色.
  • 重复(选择下一个点,将其值放入c,将零放入z并进行计算)
  • choose a point on the complex plane, say (1.01312 + 0.8324i) => this will be the value of c !
  • before the first iteration put (0, 0i) into z then iterate over a number of times as stated before => z = z^2 + c. Yes, you are squaring a point and adding that same point to it, this is a very important attribute of the Mandelbrot set. For a starter do this 50 times. This will give you a complex number as result.
  • if any part of the resulting complex number (either the Real, or the Imaginary) is equal to, or larger than 2, then we assume this point would go to infinity and we consider this point not being part of the Mandelbrot set*. This is the case when you need to color the point (this is the colorful part of the Mandelbrot set). If both part of the complex number are less than 2, we assume the point would never go to infinity (even if iterated over zillion times), and consider this point as part of the Mandelbrot set and its color will be black.
  • repeat (choose the next point, put its value into c, put zero into z and calculate)

*实际上,验证点是否是集合的一部分要复杂一些,但这对于原型来说效果很好

*actually, verifying if a point is part of the set is a bit more complicated, but this works well for prototypes

这篇关于计算mandelbrot集迭代有麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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