3D Mandelbrot Point Cloud
in
Programming Questions
•
3 years ago
Hello,
I am attempting to create a 3D/4D mandelbrot, visualized through the point cloud method. If there is anyone on here experienced enough with the math, I would appreciate some suggestions.
Here is a link where the math is coming from:
mandelbulb mathematics
Here is the code I currently have for computing the point cloud. In the draw function in the main sketch I simply have a 'displayptcloud();' inside of a push/popMatrix();
The main tab is this:
- import processing.opengl.*;
- import processing.dxf.*;
- boolean record;
- PFont font;
- void setup() {
- size(1200,800,OPENGL);
- smooth();
- hint(ENABLE_OPENGL_4X_SMOOTH);
- noStroke();
- }
- void draw () {
- background(0);
- pushMatrix();
- //navigation
- translate(width/2,height/2); //translate centre to the middle of the screen
- scale(3);//scale three times
- translate(0,0,distance);
- rotateX(alpha2);
- rotateZ(alpha1);
- translate(translate1-cx,translate2-cy,-cz*0); // translate everything to the centroid of the set
- displayptcloud();
- popMatrix();
- }
the function fractalpt is this:
- void fractalpt (float fractalx, float fractaly, float fractalz) {
- point(fractalx,fractaly,fractalz);
- }
The tab for the mouse (although this shouldn't be needed) is as follows:
- float alpha1 = -158.23;
- float alpha2 = 1.13;
- float distance = -2500;
- int mouse_x, mouse_y;
- float translate1 = -1700;
- float translate2 = 1242;
- float cx,cy,cz; //centroid
- boolean keyRelease = false;
- boolean pause=false;
- float time = 0;
- void displayposition()
- {
- print(" alpha1 = "+alpha1);
- print(" alpha2 = "+alpha2);
- print(" distance = "+distance);
- print(" translate1 = "+translate1);
- print(" translate2 = "+translate2);
- println(" ");
- }
- void keyReleased()
- {
- keyRelease = true;
- }
- void mousePressed ()
- {
- mouse_x = mouseX;
- mouse_y = mouseY;
- displayposition();
- }
- void mouseDragged()
- {
- if (mouseButton == LEFT)
- {
- alpha1 +=(mouse_x - mouseX)/100.0;
- alpha2 +=(mouse_y - mouseY)/100.0;
- }
- if (mouseButton == RIGHT)
- {
- float msx = (mouse_x - mouseX);
- float msy = (mouse_y - mouseY);
- translate1 -=( cos(alpha1)*msx + sin(alpha1)*msy)*10;
- translate2 -=( -sin(alpha1)*msx + cos(alpha1)*msy)*10;
- }
- if (mouseButton == CENTER)
- {
- distance +=(mouse_x - mouseX)/2.5+(mouse_y - mouseY)*10;
- };
- mouse_x=mouseX;
- mouse_y=mouseY;
- }
Thanks
Devin
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HERE is all of the math, which is definitely where the problem is:
- int maxiterations = 2;
- int complexx = 1000;
- int complexy = 1000;
- int complexz = 1000;
- float newx,newy,newz;
- float xmin = -2.5; float ymin = -2.0; float zmin = -2.0; float wh = 4;
- void displayptcloud () {
- float xmax = xmin + wh;
- float ymax = ymin + wh;
- float zmax = zmin + wh;
- float dx = (xmax - xmin) / (complexx);
- float dy = (ymax - ymin) / (complexy);
- float dz = (zmax - zmin) / (complexz);
- //newx = 0; newy = 0; newz = 0;
- float z = zmin;
- for(float k = 0; k < complexz; k++) {
- float y = ymin;
- for(float j = 0; j < complexy; j++) {
- float x = ymin;
- for(float i = 0; i < complexx; i++) {
- float a = x;
- float b = y;
- float c = z;
- //float k1,k2,k3,k4;
- int n = 0;
- while (n < maxiterations) {
- float a2 = sq(a);
- float a4 = (sq(a)*sq(a));
- float b2 = sq(b);
- float b4 = (sq(b)*sq(b));
- float c2 = sq(c);
- float c4 = (sq(c)*sq(c));
- float k3 = a2 + c2;
- float k2 = -sqrt( k3*k3*k3*k3*k3*k3*k3 );
- float k1 = (a4 + b4 + c4) - (6.0*b2*c2) - (6.0*a2*b2) + (2.0*c2*a2);
- float k4 = a2 - b2 + c2;
- float newx = 64.0*a*b*c*(a2-c2)*k4*(a4-6.0*a2*c2+c4)*k1*k2;
- float newy = -16.0*b2*k3*k4*k4 + k1*k1;
- float newz = -8.0*b*k4*(a4*a4 - 28.0*a4*a2*c2 + 70.0*a4*c4 - 28.0*a2*c2*c4 + c4*c4)*k1*k2;
- if ((sq(a)) + (sq(b)) + (sq(c)) > 64.0f) {
- break;
- }
- n++;
- }
- //println("xvalue" + newx);
- //println("xvalue" + newy);
- //println("xvalue" + newz);
- if (n == maxiterations) {
- fractalpt(newx,newy,newz);
- stroke(255,255,0);
- } else {
- }
- x += dx;
- }
- y += dy;
- }
- z += dz;
- }
- }
1