2

When I make a normal Mandelbrot set, it works fine. But when I try to invert it into a teardrop-like thing (see here for more context: https://www.youtube.com/watch?v=mLJJUElQMRY) it is completely distorted and looks nothing like a teardrop.

I've tried looking into it but it seems like I'm doing everything correct. I'm inverting it by dividing 1 by the 'c' variable.

Here is a section of my code which is the actual formula, this is written in processing which is just Java with added visual libraries:

zx2=zx*zx;
zy2=zy*zy;
zy = 2*zx*zy + 1.0/(y); //the "1.0/" is what makes it inverted, a normal Mandelbrot set is just y and x on its own.
zx = zx2-zy2 + 1.0/(x);

It's extremely distorted when I run the code and doesn't even look like a teardrop! Here is what it looks like:

Distorted looking image

Then I tried fixing it by implementing the code of an answer, here's the code:

zx2=zx*zx;
zy2=zy*zy;
zy = 2*zx*zy + (y/(x*x+y*y));
zx = zx2-zy2 + (x/(x*s+y*y));       

But although it does look inverted, it's still distorted and doesn't look like a teardrop. Here's a photo:

Distorted Inverted Mandelbrot.

Have I done something wrong while implementing the code?

Spektre
  • 49,595
  • 11
  • 110
  • 380
MorganS42
  • 656
  • 4
  • 21
  • 1
    Why do you think that your formulas should make the inverted mandelbrot? Do you have a reference? – Yunnosch May 18 '19 at 08:34
  • @Yunnosch The 1.0/y and the 1.0/x are what makes it inverted, a normal Mandelbrot set has just y and x on its own. – MorganS42 May 18 '19 at 08:41
  • 1
    That is not the same as the expression shown [here](https://link.springer.com/article/10.1007/BF02341047). – Weather Vane May 18 '19 at 08:48

1 Answers1

5

We need to think of c as a complex number, so in the normal Mandelbrot case, we have:

zy = 2*zx * zy + cy;
zx = zx2 - zy2 + cx;

But to get the reciprocal of c, we have to do a complex reciprocal:

zy = 2*zx * zy + (cy / (cx**2 + cy**2));
zx = zx2 - zy2 + (cx / (cx**2 + cy**2));

Of course, since c is constant from the loop's prespective, we can calculate the reciprocal before the loop. In a language like Python with complex numbers, it's a simple change from normal Mandelbrot:

c = complex(real, imaginary)

z = 0j

for i in range(iterations):
    if abs(z) >= 4.0:
        break

    z = z * z + c

to inverted Mandelbrot:

c = 1 / complex(real, imaginary)

z = 0j

for i in range(iterations):
    # ...

But if we're implementing the complex numbers ourselves, then for the normal Mandelbrot we do:

x = real
y = imaginary

zx = 0
zy = 0

for i in range(iterations):
    zx2 = zx * zx
    zy2 = zy * zy

    if ((zx2 + zy2) ** 0.5) >= 4.0:
        break

    zy = 2*zx * zy + y
    zx = zx2 - zy2 + x

and for the inverted Mandelbrot we do:

denominator = real**2 + imaginary**2

x = real / denominator
y = imaginary / denominator

zx = 0
zy = 0

for i in range(iterations):
    # ...

Bottom line, it's the difference between:

1 / complex(real, imaginary)  # correct

and:

complex(1 / real, 1 / imaginary)  # incorrect

enter image description here

cdlane
  • 40,441
  • 5
  • 32
  • 81
  • Thanks for the answer! But after implementing your code, it does look inverted by is still distorted and doesn't look like a teardrop, here it is: https://imgur.com/x7Z4K8p. – MorganS42 May 18 '19 at 22:13
  • @MorganS42, your updated code has the term `x/(x*s+y*y)` instead of `x/(x*x+y*y)` -- if that's not the cause of the current problem, provide more of your source code. – cdlane May 19 '19 at 02:00
  • that was completly it! Thanks so much for all your help, I can't believe I didn't notice that earlier, silly me. – MorganS42 May 19 '19 at 04:58
  • Do you also think you could include some sources to how you were able to convert a complex equation to an equation using x and y (representing real and imaginary numbers)? Thanks. – MorganS42 May 20 '19 at 10:06