Failed to compute itdelbrot iterations

So, I read this article: http://www.wikihow.com/Plot-the-Mandelbrot-Set-By-Hand But I got stuck in step 7. I draw a set in javascript canvas.

All I need is apparently the value of C.

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

I also read a lot about imaginary numbers, etc., but I did not quite understand how to calculate them. And they seem to me somehow useless, because in any case you have to convert them to real numbers in order to perform logical operations in javascript, for example.

Here's what it looks like: [deleted]
If you delete 2 at the end of the URL, you will see another version where I just rewrote a small C ++ snippet. But scaling is somehow strange, so I want to write it all myself.

I understood the basic concept of creating a set of mandelbrots, but, as I said, the difficult part is bothering me. Maybe there is an even simpler explanation?

+4
source share
1 answer

You must understand this first:

 z = z^2 + c 

Let me break it.

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

(a + bi) , which matches: (a + b*i)

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

Your link does not mention the most important property of a complex number, especially the property of its imaginary part, which is i == sqrt(-1) . In the field of Real numbers there is no such thing as the square root of a negative number, and that where complex numbers enter, and you can have the square root of -1. Suppose i to degree 2: i^2 == -1 , magick!

The imaginary part ( i ) should either be processed by you (a special square), or the programming language with which you work will offer a complex type that processes it for you.

Now back to the extension z^2 :

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

Let me break it as well:

  • a^2 => It's simple, it's a real number
  • bi^2 => The hard part. It really is b^2*i^2 . And we got here i^2 , which is -1 and 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

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

An example (a bit more detailed. You can imagine 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) 

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

If you want to create a Mandelbrot set, you are really looking for points on a complex plane that never go to infinity, if you repeat more than 50 times - with the iteration discussed above. The Mandelbrot set is the black part of the commonly visible Mandelbrot images, not the shiny colored part.

Mandelbort set, taken from Wikipedia

A typical workflow is this:

  • select a point on the complex plane, say (1.01312 + 0.8324i) => it will be the value of c !
  • before the first iteration puts (0, 0i) in z , then repeat several times as described above => z = z^2 + c . Yes, you square a point and add the 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.
  • if any part of the resulting complex number (either Real or Imaginary) is equal to or greater than 2, then we assume that this point goes to infinity and we consider this point that is not part of the Mandelbrot set *. This is the case when you need to color the point (this is the brightest part of the Mandelbrot set). If both parts of the complex number are less than 2, we assume that the point never goes to infinity (even if iterated more than a million times), and consider this point as part of the Mandelbrot set, and the color will be black.
  • repeat (select the next point, put its value in c , put zero in z and calculate)

* in fact, checking if a point is part of a set is a bit more complicated, but it works well for prototypes

+15
source

Source: https://habr.com/ru/post/1396079/


All Articles