News: Did you know ? you can use LaTex inside Postings on fractalforums.com!  ## The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!

 Pages: 1    Go Down       Author Topic: Menger Sponge 45 Rotation  (Read 3234 times) Description: Mathematical Structures 0 Members and 1 Guest are viewing this topic.
trafassel
Fractal Bachius Posts: 531  « Reply #15 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 Logged
trafassel
Fractal Bachius Posts: 531  « Reply #16 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 Logged
trafassel
Fractal Bachius Posts: 531  « Reply #17 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;
} Logged
mclarekin
Fractal Senior      Posts: 1739  « Reply #18 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;
} Logged
trafassel
Fractal Bachius Posts: 531  « Reply #19 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;
double holeSize=1;
int iterations=6;
x*=boxSize;
y*=boxSize;
z*=boxSize;
if(x> boxSize)return false;
if(y> boxSize)return false;
if(z> boxSize)return false;
if(x<-boxSize)return false;
if(y<-boxSize)return false;
if(z<-boxSize)return false;
for (int n = 1;n < iterations;  n++)
{
double xa=Math.Abs(x);
double ya=Math.Abs(y);
double za=Math.Abs(z);
int holeCount=0;
if(xa<holeSize) holeCount++;
if(ya<holeSize) holeCount++;
if(za<holeSize) holeCount++;
if(holeCount>=2) return false;
if(x> holeSize) x-=2*holeSize;
if(x<-holeSize) x+=2*holeSize;
if(y> holeSize) y-=2*holeSize;
if(y<-holeSize) y+=2*holeSize;
if(z> holeSize) z-=2*holeSize;
if(z<-holeSize) z+=2*holeSize;
x*=boxSize;
y*=boxSize;
z*=boxSize;
}
return true; Logged
DarkBeam
Global Moderator
Fractal Senior      Posts: 2512 Fragments of the fractal -like the tip of it « Reply #20 on: December 13, 2016, 08:33:50 PM »   Logged

No sweat, guardian of wisdom!
trafassel
Fractal Bachius Posts: 531  « Reply #21 on: December 14, 2016, 12:17:50 AM »

The 45 degree variant. Logged
trafassel
Fractal Bachius Posts: 531  « Reply #22 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)
{

double boxSize=3;
double holeSize=1.2;
double scalex=1.1;
double scaley=1.1;
double scalez=0.9;

x*=boxSize;
y*=boxSize;
z*=boxSize;
if(x> boxSize*scalex)return false;
if(y> boxSize*scalex)return false;
if(z> boxSize*scaley)return false;
if(x<-boxSize*scaley)return false;
if(y<-boxSize*scalez)return false;
if(z<-boxSize*scalez)return false;
for (int n=1;n < _cycles;  n++)
{
double xa=Math.Abs(x);
double ya=Math.Abs(y);
double za=Math.Abs(z);
int holeCount=0;
if(xa<holeSize)holeCount++;
if(ya<holeSize)holeCount++;
if(za<holeSize)holeCount++;
if(holeCount>=2)return false;
if(x> holeSize)
{
Red++;
x-=2*holeSize;
}
if(x<-holeSize)
{
Red--;
x+=2*holeSize;
}
if(y> holeSize)
{
Blue++;
y-=2*holeSize;
}
if(y<-holeSize)
{
Blue--;
y+=2*holeSize;
}
if(z> holeSize)
{
Green++;
z-=2*holeSize;
}
if(z<-holeSize)
{
Green--;
z+=2*holeSize;
}
x*=boxSize*scalex;
y*=boxSize*scaley;
z*=boxSize*scalez;
}
return true;
} Logged
mclarekin
Fractal Senior      Posts: 1739  « Reply #23 on: December 17, 2016, 10:03:50 AM »

The surface coloring looks great. I am going to try it out  Logged
trafassel
Fractal Bachius Posts: 531  « Reply #24 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. Logged
trafassel
Fractal Bachius Posts: 531  « Reply #25 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:

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)
{
double boxSize=1.8;
double holeSize=0.62;
for (int n=1;n < 17;  n++)
{
if(Math.Abs(x)>=holeSize &&
Math.Abs(y)>=holeSize &&
Math.Abs(z)>=holeSize) return false;
if(x> holeSize) x-=2*holeSize;
if(x<-holeSize) x+=2*holeSize;
if(y> holeSize) y-=2*holeSize;
if(y<-holeSize) y+=2*holeSize;
if(z> holeSize) z-=2*holeSize;
if(z<-holeSize) z+=2*holeSize;
x*=boxSize;
y*=boxSize;
z*=boxSize;
}
return true;
} Logged
 Pages: 1    Go Down
 Related Topics Subject Started by Replies Views Last post  Menger sponge fly-through 3D Fractal Generation twinbee 10 4842 February 16, 2009, 05:43:21 AM by twinbee  4D Menger sponge Sierpinski Gasket « 1 2 » makc 27 8802 December 09, 2016, 04:01:39 PM by knighty  3D menger sponge fly through Movies Showcase (Rate My Movie) DonWebber 0 1810 September 14, 2010, 01:01:18 AM by DonWebber  Through the Menger Sponge Movies Showcase (Rate My Movie) Michael Scharrer 0 469 October 17, 2015, 05:55:43 PM by Michael Scharrer  Menger Sponge, 45 Degree Rotation Gestaltlupe Gallery trafassel 0 547 November 24, 2016, 07:17:51 PM by trafassel