Welcome to Fractal Forums

Fractal Math, Chaos Theory & Research => Sierpinski Gasket => Topic started by: DarkBeam on October 25, 2015, 04:59:29 PM




Title: Smoothed MengerIfs
Post by: DarkBeam on October 25, 2015, 04:59:29 PM
It is just an idea. Here is the original code.
Code:
Menger3(x,y,z){ // (c) knighty
   r=x*x+y*y+z*z;
   for(i=0;i<MI && r<bailout;i++){
      rotate1(x,y,z);

      x=abs(x);y=abs(y);z=abs(z); // abs
      if(x-y<0){x1=y;y=x;x=x1;} // swap 1
      if(x-z<0){x1=z;z=x;x=x1;} // swap 2
      if(y-z<0){y1=z;z=y;y=y1;} // swap 3
      
      z-=0.5*CZ*(scale-1)/scale;
      z=-abs(-z); // abs
      z+=0.5*CZ*(scale-1)/scale;

      rotate2(x,y,z);
    
      x=scale*x-CX*(scale-1);
      y=scale*y-CY*(scale-1);
      z=scale*z;
      
      r=x*x+y*y+z*z;
   }
   return sqrt(x*x+y*y+z*z)*scale^(-i);
}

To make a smoothed out version we must replace all swaps and abs() with smooth functions.
The trouble is smooth the swaps :)
Defining this formula:
Code:
function s0(a) {return (a<0)?a:0;}
T=s0(x-y);
X=x-t;
Y=y+t;
It also does the trick.
Now defining...
Code:
function s1(a,b) {return (0.5*(a-sqrt(a*a+b)));} // b must be positive
T=s1(x-y,smoothfac);
X=x-t;
Y=y+t;
The bigger is the factor the smoother is the swap. Zero leads to the same result as the conditional swap. (Or it really should!)
As for smoothing abs you use sqrt(a*a+b) with the same meaning and precaution.
No renders for now :D anyone can try this?
Edit. Never mind. Fixed a stupid error


Title: Re: Smoothed MengerIfs
Post by: DarkBeam on October 25, 2015, 05:46:49 PM
Function plot using Google...
https://www.google.it/search?q=sqrt(x)&sourceid=chrome-mobile&ie=UTF-8#q=(-sqrt(x*x%2B40)%2Bx)%2F2 (https://www.google.it/search?q=sqrt(x)&sourceid=chrome-mobile&ie=UTF-8#q=(-sqrt(x*x%2B40)%2Bx)%2F2)


Title: Re: Smoothed MengerIfs
Post by: mclarekin on October 26, 2015, 12:40:15 AM
 O0

I still have an infinity of coding to do, in exploring all the links you have already supplied me with. ;D


Title: Re: Smoothed MengerIfs
Post by: thargor6 on October 26, 2015, 01:21:41 AM
No renders for now :D anyone can try this?
Just released an ALPHA-version of the JIT-version ( http://www.fractalforums.com/beta-testing/experimental-mb3d-version-with-integrated-formula-compiler-(jit)/ (http://www.fractalforums.com/beta-testing/experimental-mb3d-version-with-integrated-formula-compiler-(jit)/) ). Maybe you can hack it together by yourself :D


Title: Re: Smoothed MengerIfs
Post by: DarkBeam on October 26, 2015, 07:52:54 AM
Great Andreas and good luck Mc! :angel1:


Title: Re: Smoothed MengerIfs
Post by: cKleinhuis on October 26, 2015, 09:09:55 AM
nice experiment alex, very nice to see you really continue the development, respects for that!



Title: Re: Smoothed MengerIfs
Post by: DarkBeam on October 26, 2015, 11:46:49 AM
 ;D ;D ;D

Delphi version of MengerIfs.

Code:
[OPTIONS]
.Version = 2
.DEscale = 1
.SIpower = 2
[SOURCE]
procedure MengerIFSsmooth(var x, y, z, w: Double; PIteration3D: TPIteration3D);
var
  t: Double;
  sc, sc1, sc2: Double;
  Cx, Cy, Cz: Double;

begin
  sc := 3.0;
  sc1 := sc-1.0;
  sc2 := sc1/sc;
  Cx := 1.0; Cy := 1.0; Cz := 0.5;
  t := 9999999.0;

  x := abs(x); y := abs(y); z := abs(z);

  If x-y < 0.0 then
  begin
    t:=x; x:=y; y:=t;
  end;
  If x-z < 0.0 then
  begin
    t:=x; x:=z; z:=t;
  end;
  If y-z < 0.0 then
  begin
    t:=y; y:=z; z:=t;
  end;

  z := z - Cz*sc2;
  z := - abs(-z);
  z := z + Cz*sc2;

  x := sc*x-Cx*sc1;
  y := sc*y-Cy*sc1;
  z := sc*z;
end;
[END]

Description:

Now on to the smooth one :D

WOAH!!! Works :worm: :worm: :worm:

Code:
[OPTIONS]
.Version = 2
.DEscale = 1
.SIpower = 2
.DEoption = 2
[SOURCE]
procedure MengerIFSsmooth(var x, y, z, w: Double; PIteration3D: TPIteration3D);
var
  t: Double;
  sc, sc1, sc2: Double;
  Cx, Cy, Cz: Double;
  s: Double;

begin
  sc := 3.0;
  sc1 := sc-1.0;
  sc2 := sc1/sc;
  Cx := 1.0; Cy := 1.0; Cz := 0.5;
  t := 9999999.0;
  s := 0.005;

  x := sqrt(x*x+s); y := sqrt(y*y+s); z := sqrt(z*z+s);

  t:=x-y; t:= 0.5*(t-sqrt(t*t+s));
  x:=x-t; y:= y+t;

  t:=x-z; t:= 0.5*(t-sqrt(t*t+s));
  x:=x-t; z:= z+t;

  t:=y-z; t:= 0.5*(t-sqrt(t*t+s));
  y:=y-t; z:= z+t;

  z := z - Cz*sc2;
  z := - sqrt(z*z+s);
  z := z + Cz*sc2;

  x := sc*x-Cx*sc1;
  y := sc*y-Cy*sc1;
  z := sc*z;
  w := sc*w;
end;
[END]

Description:


Title: Re: Smoothed MengerIfs
Post by: thargor6 on October 26, 2015, 11:47:07 AM
Delphi version of MengerIfs.
Nice  :beer:

Btw, you may also use local functions here, would probably be a good approach to implement your s0/s1-function in this case, e.g.:
Code:
[SOURCE]
procedure MengerIFSsmooth(var x, y, z, w: Double; PIteration3D: TPIteration3D);
var
  t: Double;
  sc, sc1, sc2: Double;
  Cx, Cy, Cz: Double;

  function s0(const a: Double):Double;
  begin
    Result := ...
  end;

begin
  sc := 3.0;
  ...
end;


Title: Re: Smoothed MengerIfs
Post by: DarkBeam on October 26, 2015, 08:55:47 PM
Great idea Andreas; too bad I prefer a longer code for an easier asm transcription. :) But you did a wonderful job. :beer:
For the coders;
Also a different smoothing style is easily done. Replace all sqrt(t*t+s) occurrencies (also those with x y z keeping the appropriate symbols ...) with: abs(t)*t*t/(s+t*t) (unoptimized but you got the idea) ;)