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: Check out the originating "3d Mandelbulb" thread here
 
*
Welcome, Guest. Please login or register. April 23, 2024, 10:47:27 PM


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: Bizzarre Mandelbrot Result  (Read 2680 times)
0 Members and 1 Guest are viewing this topic.
asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« on: February 14, 2012, 09:02:18 AM »

I made a Mandelbrot program in Processing a little while ago that tests every pixel on the screen using z = sq(z)+c. It works just fine but I did not know how to generalize it to 3D. I found a website that had a very simple looking different method of testing points to see if they are part of the Mandelbrot set (and a generalization to 3D) and followed the instructions. To my surprise it made a different fractal. The website is here:

http://www.skytopia.com/project/fractal/mandelbrot.html#pandora

What I wrote is below. It's in the Java that Processing uses (the important part is in the while statement, I know that the rest works correctly):

float xmin = -2.5;
float ymin = -2;
float wh = 4;
int maxIterations = 100;

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

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

One last thing that was even more strange to me is that if I change two lines in the while statement to subtract Step 3 from the instructions (instead of add) I get something that looks like a Mandelbrot Set reflected over the Y axis (the left half reflects to the right). The changed lines become:

nx = cos(a*2)*sq(d)-cos(a)*d;
ny = sin(a*2)*sq(d)-sin(a)*d;

Any help or suggestions as to what might have gone wrong would be greatly appreciated.
Logged
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #1 on: February 14, 2012, 02:37:42 PM »

woooooooo some processing !
I'll try and check that as soon as a i have some free time. (i'm at work right now ...)
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #2 on: February 14, 2012, 04:01:28 PM »

hooooooo fun ! (played with the code)

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

void setup() {
  size(600, 600, P3D);
  noLoop();
}

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

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #3 on: February 14, 2012, 04:19:45 PM »

problem solved :

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

void setup() {
  size(600, 600, P3D);
  noLoop();
}

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

please see STEP 4 :

STEP 4: Finally, perform the above 3 steps again, but this time with the yellow star point replacing the old blue point (however, make sure you always use the ORIGINAL blue arrow for the final movement in step 3 (i.e. always move it by x=x+0.2 y=y+0.4). Once you've gotten the new "yellow star" point, do the same again, and AGAIN.

the original is what i called "oa" and "od" in my code.
I'm surprised i could solve this problem, as i don't really understand the explanation on http://www.skytopia.com/project/fractal/mandelbrot.html#pandora
« Last Edit: February 14, 2012, 04:21:19 PM by ker2x » Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #4 on: February 14, 2012, 04:43:24 PM »

i realise that i added a lot of modification of my own.
so here is the patch from your original code :


float xmin = -2.5;
float ymin = -2;
float wh = 4;
int maxIterations = 100;

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

void draw() {
  loadPixels();
  float xmax = xmin+wh;
  float ymax = ymin+wh;
  float dx = (xmax-xmin)/width;
  float dy = (ymax-ymin)/width;
  float x = xmin;
  for (int i = 0; i < width; i++) {
    float y = ymin;
    for (int j = 0; j < height; j++) {
      float nx = x;
      float ny = y;
      int n = 0;
      float oa = atan2(ny, nx);
      float od = sqrt(sq(nx)+sq(ny));

      while (n < maxIterations) {
        float a = atan2(ny, nx);
        float d = sqrt(sq(nx)+sq(ny));
        nx = cos(a*2)*sq(d)+cos(oa)*od;
        ny = sin(a*2)*sq(d)+sin(oa)*od;
        if (sq(nx)+sq(ny) > 4) break;
        n++;
      }
      if (n == maxIterations) pixels[i+j*width] = 0xffffff;
      else pixels[i+j*width] = 0;
      y += dy;
    }
    x += dx;
  }
  updatePixels();
}
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #5 on: February 14, 2012, 05:00:51 PM »

can you please share the code when you'll extrapolate to the 3rd dimension ? smiley
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« Reply #6 on: February 14, 2012, 05:53:28 PM »

Oh whoops, I never was too good at following the end of instructions, ha ha. Thank you for looking through it, I will post the 3D version if I wrap my head around it. Out of curiosity, do you know the name of any of the fractals that showed up?

  • In the original problem code, there was one that looked like a circle being squeezed at the top, right, bottom, and left with bumps on the surface.
  • In the original problem code, swapping nx and ny in the atan2() function made some kind of swirly Mandelbrot Set.
  • In the weird subtraction version of the problem code, was a reflected Mandelbrot Set over the Y axis.
  • In your first code, there was a fractal that was made up of dividing lines.
Logged
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #7 on: February 15, 2012, 10:44:04 AM »

Oh whoops, I never was too good at following the end of instructions, ha ha. Thank you for looking through it, I will post the 3D version if I wrap my head around it. Out of curiosity, do you know the name of any of the fractals that showed up?

  • In the original problem code, there was one that looked like a circle being squeezed at the top, right, bottom, and left with bumps on the surface.
  • In the original problem code, swapping nx and ny in the atan2() function made some kind of swirly Mandelbrot Set.
  • In the weird subtraction version of the problem code, was a reflected Mandelbrot Set over the Y axis.
  • In your first code, there was a fractal that was made up of dividing lines.

In most of my tests, it looked like Julia.
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« Reply #8 on: February 17, 2012, 12:57:00 AM »

I think I figured out the 3D one, I'm not really sure to be honest. The problem is that I don't know how to represent it nicely in Processing. Right now I have it representing only points that reached the max iteration count and I don't know how to light it properly.

I spent a few days wrapping my head around getting x, y, z coordinates to be spherical coordinate angles. If I generalized it correctly then this should be the image from that link (the white fractal with the glowing orange aura): http://www.skytopia.com/project/fractal/mandelbrot.html#pandora

float xmin = -2;
float ymin = -2;
float zmin = -2;
float wh = 4;
int boxLength = 200;
int maxIterations = 1;
int screenSize = 400;
float temp = 0;

void setup() {
  size(screenSize, screenSize, P3D);
  noLoop();
}

void draw() {
  background(255);
  translate((screenSize-boxLength)/2, (screenSize-boxLength)/2);
  float xmax = xmin+wh;
  float ymax = ymin+wh;
  float zmax = zmin+wh;
  float dx = (xmax-xmin)/boxLength;
  float dy = (ymax-ymin)/boxLength;
  float dz = (zmax-zmin)/boxLength;
  float x = xmin;
  for (int i = 0; i < boxLength; i++) {
    float y = ymin;
    for (int j = 0; j < boxLength; j++) {
      float z = zmin;
      for (int k = 0; k < boxLength; k++) {
        float rad = sqrt(x*x+y*y+z*z);
        float phi = atan2(z, x);
        float phiLength = sqrt(x*x+z*z);
        float theta = atan2(phiLength, y);
        float nx = x;
        float ny = y;
        float nz = z;
        int n = 0;
        while (n < maxIterations) {
          float nRad = sqrt(nx*nx+ny*ny+nz*nz);
          float nPhi = atan2(nz, nx);
          float nPhiLength = sqrt(nx*nx+nz*nz);
          float nTheta = atan2(nPhiLength, ny);
          nx = cos(nPhi*2)*sin(nTheta*2)*nRad*nRad;
          ny = cos(nTheta*2)*nRad*nRad;
          nz = sin(nPhi*2)*sin(nTheta*2)*nRad*nRad;
          nx += cos(phi)*sin(theta)*rad;
          ny += cos(theta)*rad;
          nz += sin(phi)*sin(theta)*rad;
          if (nx*nx+ny*ny+nz*nz > 4) break;
          n++;
        }
        if (n == maxIterations) point(i, j, k);
        z += dz;
      }
      y += dy;
    }
    x += dx;
  }
  println("Done");
}
« Last Edit: February 17, 2012, 12:58:32 AM by asimes » Logged
asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« Reply #9 on: February 17, 2012, 01:06:06 AM »

This is a little better:

EDIT: Changed a bit:

float xmin = -2;
float ymin = -2;
float zmin = -2;
float wh = 4;
int boxLength = 200;
int maxIterations = 255;
int screenSize = 400;
float temp = 0;

void setup() {
  size(screenSize, screenSize, P3D);
  noStroke();
  noLoop();
}

void draw() {
  background(255);
  translate((screenSize-boxLength)/2, (screenSize-boxLength)/2);
  float xmax = xmin+wh;
  float ymax = ymin+wh;
  float zmax = zmin+wh;
  float dx = (xmax-xmin)/boxLength;
  float dy = (ymax-ymin)/boxLength;
  float dz = (zmax-zmin)/boxLength;
  float x = xmin;
  for (int i = 0; i < boxLength; i++) {
    float y = ymin;
    for (int j = 0; j < boxLength; j++) {
      float z = zmin;
      for (int k = 0; k < boxLength; k++) {
        float rad = sqrt(x*x+y*y+z*z);
        float phi = atan2(z, x);
        float phiLength = sqrt(x*x+z*z);
        float theta = atan2(phiLength, y);
        float nx = x;
        float ny = y;
        float nz = z;
        int n = 0;
        while (n < maxIterations) {
          float nRad = sqrt(nx*nx+ny*ny+nz*nz);
          float nPhi = atan2(nz, nx);
          float nPhiLength = sqrt(nx*nx+nz*nz);
          float nTheta = atan2(nPhiLength, ny);
          nx = cos(nPhi*2)*sin(nTheta*2)*nRad*nRad;
          ny = cos(nTheta*2)*nRad*nRad;
          nz = sin(nPhi*2)*sin(nTheta*2)*nRad*nRad;
          nx += cos(phi)*sin(theta)*rad;
          ny += cos(theta)*rad;
          nz += sin(phi)*sin(theta)*rad;
          if (nx*nx+ny*ny+nz*nz > 4) break;
          n++;
        }
        if (n != 0) {
          translate(i, j, k);
          fill(n*19%255, n*11%255, n*7%255, n);
          box(1);
          translate(-i, -j, -k);
        }
        z += dz;
      }
      y += dy;
    }
    x += dx;
  }
  println("Done");
}
« Last Edit: February 17, 2012, 01:21:01 AM by asimes » Logged
asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« Reply #10 on: February 17, 2012, 01:45:53 AM »

It took a little while (a few min) but setting:

boxLength = 500;
screenSize = 800;

Then the rendering section to:

if (n > 10) {
  translate(i, j, k);
  fill(n*3%255, n*2%255, n%255, n);
  box(1);
  translate(-i, -j, -k);
}

Makes a much more reasonable image. Still experimenting with color, transparency, and hopefully soon lighting
Logged
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #11 on: February 17, 2012, 11:24:01 PM »

Thank you, i will try !  grin
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #12 on: February 21, 2012, 07:04:02 PM »

huh...
you're checking 500x500x500 points smiley))

Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
3D Mandelbrot Movies Showcase (Rate My Movie) David Makin 0 6799 Last post December 09, 2006, 11:38:14 PM
by David Makin
PROCESS VS RESULT Non-Fractal related Chit-Chat Bent-Winged Angel 10 2543 Last post November 30, 2010, 08:37:51 PM
by Wel lEnTaoed
Interesting result from well-known idea on ff Programming David Makin 4 1587 Last post January 05, 2012, 11:56:03 AM
by David Makin
Getting weird result with Real iteration count Help & Support XSource 3 306 Last post August 26, 2012, 11:13:20 AM
by simon.snake
result varies on different PC's bug reporting Sitting Duck 2 1146 Last post April 30, 2013, 07:26:05 PM
by Sitting Duck

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.214 seconds with 28 queries. (Pretty URLs adds 0.011s, 2q)