Title: Menger Sponge 45 Rotation Post by: trafassel on November 24, 2016, 11:26:56 PM // Gestaltlupe 3.4
double _scale=4; double _offsetX=1.5; double _offsetY=1.5; double _offsetZ=1.5; double _bailout=2; double _angleX=0; double _angleY=0; double _angleZ=0; public override void Init() { base.Init(); // Plaese remove this after pressing 2 times the button above: // (This set fixed formula Parameters) if(GetString("intern.Formula.TempUpdateVal")!="021462bd1ab1887e87f23a9ace4f4e0a") { SetParameterBulk(@"Formula.Parameters: angleX=0 angleY=0 angleZ=45 bailout=2 offsetX=2.1 offsetY=1 offsetZ=1 scale=2 Formula.Static: Cycles=12 Julia=1 jx=0.9 jy=0 jz=0 Scene: CenterX=0.0965003528449048 CenterY=-1.34226795790199 CenterZ=0.160980835845237 Radius=0.349530254720366 Transformation.Camera: AngleX=-39.2596575417366 AngleY=74.1173281658452 AngleZ=-99.2265259659284 IsometricProjection=0 Position=1 intern.Formula: TempUpdateVal=021462bd1ab1887e87f23a9ace4f4e0a"); } // Load current Parameters: _scale=GetOrSetDouble("scale"); _offsetX=GetOrSetDouble("offsetX"); _offsetY=GetOrSetDouble("offsetY"); _offsetZ=GetOrSetDouble("offsetZ"); _bailout=GetOrSetDouble("bailout"); _angleX=Math.PI/180.0*GetOrSetDouble("angleX"); _angleY=Math.PI/180.0*GetOrSetDouble("angleY"); _angleZ=Math.PI/180.0*GetOrSetDouble("angleZ"); } // Menger Sponge public override bool GetBool(double x,double y,double z) { // Switch between mandel and julia mode: double jx,jy,jz; if (_isJulia) { jx=_jx; jy=_jy; jz=_jz; } else { jx=x; jy=y; jz=z; x=_jx; y=_jy; z=_jz; } for (int n=1;n < _cycles; n++) { // Menger Sponge Formula: x=Math.Abs(x); y=Math.Abs(y); z=Math.Abs(z); if(x>_bailout)return false; if(y>_bailout)return false; if(z>_bailout)return false; if (x<y) { double a=x; x=y; y=a; } if (x< z) { double a=x; x=z; z=a; } if (y<z) { double a=y; y=z; z=a; } x=_scale*x-_offsetX*(_scale-1); y=_scale*y-_offsetY*(_scale-1); z=_scale*z-_offsetZ*(_scale-1); if(z<-0.5*_offsetZ*(_scale-1.0))z+=_offsetZ*(_scale-1.0); if(_angleX!=0)Rotate(_angleX,ref y,ref z); if(_angleY!=0)Rotate(_angleY,ref x,ref z); if(_angleZ!=0)Rotate(_angleZ,ref x,ref y); // Julia / Mandel iteration: x+=jx; y+=jy; z+=jz; } return true; } void Rotate(double angle,ref double x,ref double y) { double re=Math.Cos(angle ); double im=Math.Sin(angle ); double a=re * x-im * y; y=re * y+im * x; x=a; } Title: Re: Menger Sponge 45 Rotation Post by: trafassel on November 24, 2016, 11:40:56 PM angleX=45 angleY=0 angleZ=0 bailout=230
offsetX=1 offsetY=0.666666666666667 offsetZ=0.5 scale=3 Formula.Static: Cycles=12 Julia=1 jx=0.833333333333333 jy=0 jz=0 Title: Menger Sponge degree 45 cycles 16 Post by: trafassel on November 25, 2016, 09:32:20 PM angleX=0 angleY=0 angleZ=0
bailout=230 offsetX=1.05 offsetY=1 offsetZ=1 scale=2.2 Formula.Static: Cycles=16 Julia=1 jx=0.575 jy=0 jz=0 Title: Re: Menger Sponge 45 Rotation Post by: trafassel on November 25, 2016, 10:05:32 PM 18 Iterations
Title: Re: Menger Sponge 45 Rotation Post by: trafassel on November 27, 2016, 02:05:45 PM Some parameter variations:
https://www.youtube.com/watch?v=RjTGNUG-yGY&feature=youtu.be Title: Re: Menger Sponge 45 Rotation Post by: trafassel on November 30, 2016, 07:53:37 AM Same formula, but the line:
if( z<-0.5*_offsetZ*(_scale-1.0)) z+=_offsetZ*(_scale-1.0); ist removed: Fractal Parameters: angleX=0 angleY=0 angleZ=45 bailout=2 offsetX=1.1 offsetY=1.2 offsetZ=1 scale=1.8 Cycles=100 Julia=1 jx=0.1 jy=0.1 jz=0.225 Scene Parameters: CenterX=-0.825851928838657 CenterY=-0.137484062991961 CenterZ=-0.263178096264692 Radius=1.57641612156358E-05 AngleX=71.9789945332988 AngleY=28.6324642779303 AngleZ=-63.414564994788 IsometricProjection=0 Position=1 Title: Re: Menger Sponge 45 Rotation Post by: trafassel on November 30, 2016, 07:57:54 AM Here you see a cut in the same Menger Sponge spiral. The green surface belongs to the "inside" while the grey very regular looking structures is an "outside view".
Title: Re: Menger Sponge 45 Rotation Post by: mclarekin on November 30, 2016, 09:27:23 AM The last to images are really cool, I have not seen that shape before O0 O0 O0
The attached transform works well with menger sponges ( less so for other fractals :sad1:). And I note that the coder seems to have forgotten to put in a linear DE adjustment for the scale ( hmmm??? that must have been me :embarrass:) I will go and fix that now, and it should work better. :) Title: Re: Menger Sponge 45 Rotation Post by: mclarekin on November 30, 2016, 10:34:40 AM I found a weird "i -1" in the code, how it got there I do not know. :embarrass:
This is what it should look like, (now I better go and fix the 4D version.) Code: /** Title: Re: Menger Sponge 45 Rotation Post by: trafassel on December 01, 2016, 07:47:51 AM mclarekin wrote:
Quote And I note that the coder seems to have forgotten to put in a linear DE adjustment for the scale ( hmmm??? that must have been me ) There is a simple reason for this: I hardly ever use DE in my renderings. DE adds additional lines to the formula (i like simpleness) and it was not very helpful in finding the 3D mandelbrot fractal. At least for me. Disadvantage of not using distance estimatation is longer rendering time and often noisy surface normals - especially for some grailish looking examples, like the following one (yes, there are fractal doughnuts in the box). Quote // Menger Sponge Tree public override bool GetBool(double x,double y,double z) { double sin45 = Math.Sqrt(0.5); double scale = 1.81; double offsetX = 1.15; double offsetY = 0.932; double offsetZ = 1.01; for (int n=1;n<100;n++) { x = Math.Abs(x); y = Math.Abs(y); z = Math.Abs(z); // Bailout Condition: if (x>2) return false; if (y>2) return false; if (z>2) return false; if (x<y) { double a=x; x=y; y=a; } if (x<z) { double a=x; x=z; z=a; } if (y<z) { double a=y; y=z; z=a; } x = scale*x - offsetX*(scale-1); y = scale*y - offsetY*(scale-1); z = scale*z - offsetZ*(scale-1); // Rotate x,y plane by 45 degree: double xtemp = sin45 * ( x - y ); y = sin45 * ( y + x ); x = xtemp; } return true; } Here the menger sponge tree lies in the center of the box (CenterX=-0.0945155196775858 CenterY=-0.130152813333983 CenterZ=-0.0796293685094792 Radius=0.261524932786483). Title: Re: Menger Sponge 45 Rotation Post by: trafassel on December 02, 2016, 12:30:11 PM A cut through one of the doughnuts.
Title: Re: Menger Sponge 45 Rotation Post by: trafassel on December 05, 2016, 07:58:07 PM Formula.Parameters:
angleX=0 angleY=0 angleZ=45 bailout=3 offsetX=1.2 offsetY=1.1 offsetZ=0.8 scale=1.6 Formula.Static: Cycles=75 Julia=1 jx=0 jy=0 jz=0 Scene: CenterX=-0.817698103133137 CenterY=1.2024566146392 CenterZ=0.484242312734027 Radius=0.0135254036224944 Title: Re: Menger Sponge 45 Rotation Post by: trafassel on December 06, 2016, 09:12:28 PM I do not notice that Krzysztof Marczak has made 2013 a better version of my video in reply #4 .At minute 3:00 you see the broken picture frame of my first image. https://www.youtube.com/watch?v=NIWz3BuE4nE&feature=youtu.be&a
The only missing thing was a inner view of a menger sponge with 100 iterations, which seems to be unexplored. Here is an outer view of the 45° menger sponge with a cut at z>0. Formula.Parameters: angleX=0 angleY=0 angleZ=45 bailout=6000000 offsetX=0.6 offsetY=2.8 offsetZ=0 scale=1.35 Formula.Static: Cycles=75 Julia=1 jx=0.15 jy=0 jz=0 Title: Re: Menger Sponge 45 Rotation Post by: DarkBeam on December 06, 2016, 10:33:37 PM This is REALLY interesting thanks :beer:
Title: Re: Menger Sponge 45 Rotation Post by: mclarekin on December 07, 2016, 12:10:08 AM They are so good, so many different shapes (you can see where my last gallery post came from :) thanks)
Title: Re: Menger Sponge 45 Rotation Post by: trafassel on December 07, 2016, 07:24:10 AM Formula.Parameters: angleX=0 angleY=0 angleZ=45 bailout=6000000000 offsetX=0.88 offsetY=1.272 offsetZ=1.4 scale=1.5 zUpperBound=12 Formula.Static: Cycles=75 Julia=1 jx=0.05 jy=0 jz=0 Scene: CenterX=0.641905372680213 CenterY=0.339207258021939 CenterZ=-0.262591944640448 Radius=0.249229000878406 Transformation.Camera: AngleX=175.668590010273 AngleY=-27.0356750479037 AngleZ=-171.080170533749 IsometricProjection=0 Position=1
Title: Re: Menger Sponge 45 Rotation Post by: trafassel on December 09, 2016, 07:22:06 PM Formula.Parameters: angleX=0 angleY=0 angleZ=45 bailout=3 offsetX=2 offsetY=2.5 offsetZ=2.5 scale=1.56 Formula.Static: Cycles=75 Julia=1 jx=0.05 jy=0 jz=0
Scene: CenterX=-1.33456370239741 CenterY=0.263163682905943 CenterZ=0.216002920489848 Radius=0.672939928707691 Transformation.Camera: AngleX=-44.373124365217 AngleY=63.4414563477275 AngleZ=-96.3279863410774 IsometricProjection=0 Position=1 Title: Re: Menger Sponge 45 Rotation Post by: trafassel on December 12, 2016, 11:45:58 PM Here I remove the coordinate swap and add some additional conditions. The result fractal ist the same Menger Sponge, but the rotation only applies to one plane.
double _scale=3; double _offsetX=2; double _offsetY=2; double _offsetZ=2; double _bailout=3; double _angleX=0; double _angleY=45; double _angleZ=0; // _cycles=8 public override bool GetBool(double x,double y,double z) { for (int n=1;n < _cycles; n++) { x=Math.Abs(x); y=Math.Abs(y); z=Math.Abs(z); if(x>_bailout)return false; if(y>_bailout)return false; if(z>_bailout)return false; x=_scale*x-_offsetX*(_scale-1); y=_scale*y-_offsetY*(_scale-1); z=_scale*z-_offsetZ*(_scale-1); if(x<y && x<z && x<-0.5*_offsetX*(_scale-1.0))x+=_offsetX*(_scale-1.0); else if(y<x && y<z && y<-0.5*_offsetY*(_scale-1.0))y+=_offsetY*(_scale-1.0); else if(z<x && z<y && z<-0.5*_offsetZ*(_scale-1.0))z+=_offsetZ*(_scale-1.0); if(_angleX!=0)Rotate(_angleX,ref y,ref z); if(_angleY!=0)Rotate(_angleY,ref x,ref z); if(_angleZ!=0)Rotate(_angleZ,ref x,ref y); x+=_jx; y+=_jy; z+=_jz; } return true; } void Rotate(double angle,ref double x,ref double y) { double re=Math.Cos(angle ); double im=Math.Sin(angle ); double a=re * x-im * y; y=re * y+im * x; x=a; } Title: Re: Menger Sponge 45 Rotation Post by: mclarekin on December 13, 2016, 05:09:53 AM I must try out the conditional rotate. With some fractals I can only choose to rotate one of the three axis (otherwise too distorted), this might make those formula faster :) if(_angleX!=0)Rotate(_angleX,ref y,ref z); if(_angleY!=0)Rotate(_angleY,ref x,ref z); if(_angleZ!=0)Rotate(_angleZ,ref x,ref y); I have been exploring mixing conditional and non-conditional Menger iterations in 4D but have not tried it in 3D, but it would look like this at the end of a standard 3D Menger.. z = fabs( z + preAdd ); if (z.x - z.y < 0.0f){temp = z.y; z.y = z.x; z.x = temp;} if (z.x - z.z < 0.0f){temp = z.z; z.z = z.x; z.x = temp;} if (z.y - z.z < 0.0f){temp = z.z; z.z = z.y; z.y = temp;} z *= 3.0f; z.x -= 2.0f; z.y -= 2.0f; if (i >= startIter && i < stopIter) { if (z.z > 1.0f) z.z -= 2.0f; } else { z.z-=2.0f; } Those additional conditions you have added look interesting Title: Re: Menger Sponge 45 Rotation Post by: trafassel on December 13, 2016, 08:27:09 PM The additional conditions I have only added, because I skipped the coordinate swap. The coordinates are now not sorted to x<y<z.
Also equivalent to the original formula ist my following naive approach. This is not optimized code, but its simple and is perhaps more stable to additional transformations. Code: double boxSize=3; Title: Re: Menger Sponge 45 Rotation Post by: DarkBeam on December 13, 2016, 08:33:50 PM :spiral: :thumbsup1:
Title: Re: Menger Sponge 45 Rotation Post by: trafassel on December 14, 2016, 12:17:50 AM The 45 degree variant.
Title: Colors Post by: trafassel on December 16, 2016, 01:08:20 AM Coloring the surface according to the direction of the translation gives a nice surface coloring.
(Scene: CenterX=-0.932873944699854 CenterY=0.899375847775146 CenterZ=1.16693107216321 Radius=0.18692775797436 Transformation.Camera: AngleX=-171.967389672199 AngleY=-47.8088737441608 AngleZ=73.6703503820553 IsometricProjection=0 Position=1 ) Code: public override bool GetBool(double x,double y,double z) Title: Re: Menger Sponge 45 Rotation Post by: mclarekin on December 17, 2016, 10:03:50 AM The surface coloring looks great. I am going to try it out :)
Title: Re: Menger Sponge 45 Rotation Post by: trafassel on December 17, 2016, 12:04:27 PM Quote The surface coloring looks great. I am going to try it out. This would be cool. Some areas are grey because I implemented in my renderer a "color threshold". Without this threshold the corresponding surface would be drawn in pastel colors. Title: Re: Menger Sponge 45 Rotation Post by: trafassel on December 17, 2016, 01:17:32 PM I like simple formulas. Here is another one. I removed the box boundary restriction and change the "hole indicator". The scene is located at: CenterX=0.0537731690329398 CenterY=0.986837787113877 CenterZ=0.993711945778967 Radius=0.0175530009711978 Transformation.Camera: AngleX=-104.327115785263 AngleY=-20.6946703978129 AngleZ=-132.683623253497 IsometricProjection=0 Position=1 Code: public override bool GetBool(double x,double y,double z) |