Logo by MandelBRO - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Visit the official fractalforums.com Youtube Channel
 
*
Welcome, Guest. Please login or register. March 29, 2024, 12:46:18 AM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Mandelbrot to Mandelbulb  (Read 3105 times)
0 Members and 1 Guest are viewing this topic.
asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« on: February 26, 2012, 03:22:02 PM »

I've gotten comfortable with programming the Mandelbrot (2D) after having played with it for a long time and want to generalize it to a Mandelbulb (3D). I have two different methods at the moment for making a Mandelbrot:

1. z = sq(z)+c method (where I test every point through this equation):
- I like this method and understand why it works
- Fast
- It is easy enough to set the equation to higher powers (multiply more binomials)
- I have no idea how to generalize it to 3D

2. Rotation method (based on following these instructions): http://www.skytopia.com/project/fractal/mandelbrot.html#pandora
- It does correctly make a Mandelbrot but I don't understand why
- Slow
- I don't know how to set higher powers
- Making it work in 3D seems to just require Spherical Positioning instead of Polar Positioning

If anyone reading this has Processing installed you can check out simplified versions of either code:

- Equation method:
Code:
float xmin = -2.5;
float ymin = -2.0;
float wh = 4;
int maxIterations = 255;

void setup() {
  size(800, 800, P2D);
}

void draw() {
  loadPixels();
  float xmax = xmin+wh;
  float ymax = ymin+wh;
  float dx = (xmax-xmin)/width;
  float dy = (ymax-ymin)/height;
  float x = xmin;
  for (int i = 0; i < width; i++) {
    float y = ymin;
    for (int j = 0;  j < height; j++) {
      float zr = x;
      float zi = y;
      int n = 0;
      while (n < maxIterations) {
        float zrr = zr*zr;
        float zii = zi*zi;
        float twori = 2*zr*zi;
        zr = zrr-zii+x;
        zi = twori+y;
        if (zrr+zii > 16) break;
        n++;
      }
      if (n == maxIterations) pixels[i+j*width] = 0;
      else pixels[i+j*width] = color(n);
      y += dy;
    }
    x += dx;
  }
  updatePixels();
  noLoop();
}

- Rotation method:
Code:
float xmin = -2.5;
float ymin = -2;
float wh = 4;
int maxIterations = 255;

void setup() {
  size(800, 800, P2D);
  noLoop();
}

void draw() {
  loadPixels();
  float xmax = xmin+wh;
  float ymax = ymin+wh;
  float dx = (xmax-xmin)/width;
  float dy = (ymax-ymin)/height;
  float x = xmin;
  for (int i = 0; i < width; i++) {
    float y = ymin;
    for (int j = 0; j < height; j++) {
      float a = atan2(y, x);
      float d = sqrt(x*x+y*y);
      float nx = x;
      float ny = y;
      int n = 0;
      while (n < maxIterations) {
        float na = atan2(ny, nx);
        float nd = sqrt(nx*nx+ny*ny);
        nx = cos(na*2)*nd*nd+cos(a)*d;
        ny = sin(na*2)*nd*nd+sin(a)*d;
        if (nx*nx+ny*ny > 16) break;
        n++;
      }
      if (n == maxIterations) pixels[i+j*width] = 0;
      else pixels[i+j*width] = color(n);
      y += dy;
    }
    x += dx;
  }
  updatePixels();
}

I would strongly prefer to use the equation method although I don't know how to test 3D space like this. In 2D I just test the x-axis for real numbers and the y-axis for imaginary numbers so it would be great if this could be generalized for 3D space. If not then any help with setting higher powers for the rotation method would be appreciated.
Logged
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #1 on: February 26, 2012, 03:35:08 PM »

for better understanding the triplex variant, just use the polar coordinates for your 2d mandelbrot, this way you magically can create exponents of rational numbers, e.g.2,5 this isnt possible with your int power method where you repeat the squaring ... from the polar exponentiation the bulb method arose, because it was just straightforward to include another angle in the polar exponentiation, as a reminder polar exponentiation on complex numbers equals to exponentiating the distance, and multiplying the angles ... if i still got this right
Logged

---

divide and conquer - iterate and rule - chaos is No random!
asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« Reply #2 on: February 26, 2012, 04:47:27 PM »

...I just realized using different powers for the rotation one is really easy:

nx = cos(na*power)*pow(nd, power)+cos(a)*d;
ny = sin(na*power)*pow(nd, power)+sin(a)*d;

instead of:

nx = cos(na*2)*nd*nd+cos(a)*d;
ny = sin(na*2)*nd*nd+sin(a)*d;

Although, you are right, this does just seem to magically work. I have no idea why the tutorial I followed works at all to be honest, it just correctly makes a Mandelbrot. I'm pretty sure I can make my own Mandelbulb from this now but I'd like to understand how to do it the other way for conceptual reasons (also it is waaaaaay faster than the rotation method). Could you point me in a direction where I might figure this out please?
Logged
bib
Global Moderator
Fractal Senior
******
Posts: 2070


At the borders...


100008697663777 @bib993
WWW
« Reply #3 on: February 26, 2012, 05:38:33 PM »


- It does correctly make a Mandelbrot but I don't understand why


Because it's the same as the first method smiley

http://en.wikipedia.org/wiki/Euler's_formula
Logged

Between order and disorder reigns a delicious moment. (Paul Valéry)
asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« Reply #4 on: February 28, 2012, 06:30:43 AM »

I have a 3D Mandelbulb finally working in Processing. I used the rotation method but with Spherical Coordinates and unfortunately it is really, really slow. I tried rendering a bounding box of 400x400x400 points and it took about an hour. Is this normal? I feel like if I can generalize the link Bib put it would be much faster.

The current method takes a point in Cartesian Coordinates (x, y, z), converts it Spherical Coordinates (r, theta, phi), applies the rotation similarly to the rotation code I posted above but in 3D obviously, stores the new point as Cartesian Coordinates again, and then tests the new point in a while loop to see if it tends toward infinity. This is probably why it is so slow and why I'd like to use the other method (if it is possible?).

Bib, thank you for the link although the math is still currently over my head. I'm looking into tutorials on using imaginary numbers as exponents and then attempting to tackle translating the rotation method. I don't really understand the math from the wikipedia article yet, although it seems to have an explanation on the relationship between the equation and rotation method but in 2D.

If anyone could help me understand what is going on in the article Bib put I'd really appreciate it. Also I have a new problem which is how to represent the data. Right now I just represent points with spheres but I'll tackle that problem after I have the code running at a reasonable speed.
Logged
bib
Global Moderator
Fractal Senior
******
Posts: 2070


At the borders...


100008697663777 @bib993
WWW
« Reply #5 on: February 28, 2012, 09:22:18 AM »

I can't help much about programming but I can explain complex numbers.

Don't worry too much about the imaginary number as an exponent. Let's assume it's just a practical notation. Note however that Euler's formula is probably the most elegant and intriguing formula of all mathematics because it features some of the most important and mysterious numbers in maths : e, i, 1, pi

e^i*pi=-1

Why the methods are the same is very simple. Any complex number can be written either in cartesian coordinates x+iy or in polar coordinates r*e^i*theta. With x=r*cos(theta) and y=r*sin(theta). r is the distance to origin, and theta is the angle to the x axis. So squaring a number (x+iy)²=x²-y²+2ixy is the same as doing r²*e^i2*theta : you have squared the distance and doubled the angle. Hence the equivalence of the 2 methods.

Euler's formula e^i*pi=-1 means that when you rotate the  number 1 (x=1, y=0) of 180° (pi) around the origin, then you end up on the other side (x=-1, y=0).

Basically the use of i as an exponent of e is like a rotation operator.

The original idea of the Mandelbulb was to transpose the rotation method to 3D, using the elevation angle in addition to theta, instead of trying with do to it with cartesian coordinates and matrix calculation.
« Last Edit: February 28, 2012, 09:40:40 AM by bib » Logged

Between order and disorder reigns a delicious moment. (Paul Valéry)
Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #6 on: February 28, 2012, 01:28:21 PM »

While you can create a trigonometric-free version of the Mandelbulb formula (search Fractal Forums), it won't make your renderings that much faster.

Most 3D fractals tool use distance estimated rendering to speed up calculations (I've written an introduction to this here). This will be much faster (but also more complex) than the grid approach.
Logged
asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« Reply #7 on: February 29, 2012, 08:48:21 AM »

Bib, I know you said not to worry about imaginary exponents but I don't think I can program this speed-up if I don't understand. I tried some searches on google for an explanation on how to use some imaginary number as an exponent to another number but I just get results for Euler's formula or examples of how to easily see what 'i' raised by an exponent will be. What I want to figure out would be for example:

2^i = huh?
2^2i = huh?
2^3i = huh?

The reason I'm using Cartesian Coordinates is because my Mandelbulb is inside of a box of "voxels". By that I mean I make a box of arbitrary size (for example 400x400x400) and test every (x, y, z) point inside. Maybe I'm thinking about this in the wrong way? It seems like your explanation for Euler's formula is for 2D, does it generalize to 3D? I don't understand how the complex plane is generalized by my 3D rotation method, I just know that points on a complex plane are converted to Polar Coordinates in the 2D rotation version and I know how to generalize 2D rotation to 3D.

Sythopia, I'm having a hard time finding an explanation on this as well. I think the problem is I don't know the technical name of what I'm searching for, I just call it the "equation method". What would a non-trig version be called?

Even if I turn my rendering off (I don't represent the points I tested in any way whatsoever) it still takes about a minute and a half to test 400x400x400 points. I looked through your article to get a feel of what distance estimation is, I really like it, the results look great. I'm just kind of obsessing over the actual point testing before I get into rendering. I will definitely try out the distance estimation rendering after.
Logged
asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« Reply #8 on: February 29, 2012, 09:01:47 AM »

Ha ha ha, I didn't realize writing three question marks would make a confused guy face.

I was rereading the posts and realized cKleinhuis mentioned triplex numbers. I found this: http://www.fractalforums.com/theory/triplex-algebra/

Sythopia, is that the non-trig form you were talking about? I don't quite understand it yet but I guess I'll just keep rereading it until it makes enough sense to be programmed.
Logged
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
A new mandelbulb I think Theory Tglad 0 3358 Last post November 28, 2009, 05:13:14 AM
by Tglad
Mandelbulb Bitten, and finding the MANDELBROT again. Meet & Greet mrrgu 13 4900 Last post January 06, 2010, 05:01:57 PM
by Nahee_Enterprises
My first Mandelbulb Mandelbulb Implementation spooky 6 5809 Last post January 06, 2010, 10:10:50 PM
by spooky
2d Mandelbrot in Mandelbulb? The 3D Mandelbulb avvie 5 5507 Last post February 15, 2010, 09:57:08 AM
by bib
How do I convert a Mandelbrot to a Mandelbulb? 3D Fractal Generation Bottleneck 4 3326 Last post December 03, 2011, 10:01:13 PM
by huminado

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.199 seconds with 24 queries. (Pretty URLs adds 0.01s, 2q)