Welcome to Fractal Forums

Fractal Math, Chaos Theory & Research => Sierpinski Gasket => Topic started by: Imagyx on May 19, 2016, 12:26:26 PM




Title: A Question about the Menger fractal
Post by: Imagyx on May 19, 2016, 12:26:26 PM
Hi there  :)

I'd like to know if it's possible to have the menger sponge with a low number of "holes" but sharp edges?
In my image there's maxIterM = 3 because I don't want more holes in it.
The problem is, that all "boxes" look like balls rather.
Threshold, number of rays etc. is fine. I think I need to work with abs() instead of sqrt() here, but some experiments I made failed...

The following code is from a thread in this forum from some years ago.
I only changed the syntax to fit java.

Code:
void DE(V3D w0) {
double x = w0.getX();
double y = w0.getY();
double z = w0.getZ();

double r2 = x * x + y * y + z * z;
double CX = 1.0;
double CY = 1.0;
double CZ = 1.0;
int iter = 0;
while(iter < maxIterM && r2 < bailout){

x = Math.abs(x);
y = Math.abs(y);
z = Math.abs(z);
if(x - y < 0){
double x1 = y;
y = x;
x = x1;
}
if(x - z < 0){
double x1 = z;
z = x;
x = x1;
}
if(y - z < 0){
double y1 = z;
z = y;
y = y1;
}

x = scale * x - CX * (scale - 1);
y = scale * y - CY * (scale - 1);
z = scale * z;
if(z > 0.5 * CZ * (scale - 1)){
z -= CZ * (scale - 1);
}
r2 = x * x + y * y + z * z;
iter++;
}
dist = (Math.sqrt(x * x + y * y + z * z) - 2) * Math.pow(scale, -iter * refine);
}


I think this relates to the sierpinsky triangle as well. I don't have sharp edges there either for a low iteration count.
But I want them so bad :sad1:
Thanks in advance for any help  :)

Code:
void DE(V3D p) {
double x = p.x;
double y = p.y;
double z = p.z;
double r = x * x + y * y + z * z;
int i = 0;
for(; i < iterSierp && r < maxRadius ; i++){
if(x + y < 0){
double x1 = -y;
y = -x;
x = x1;
}
if(x + z < 0){
double x1 = -z;
z = -x;
x = x1;
}
if(y + z < 0){
double y1 = -z;
z = -y;
y = y1;
}
x = scale * x - (scale - 1);
y = scale * y - (scale - 1);
z = scale * z - (scale - 1);
r = x * x + y * y + z * z;
}
dist = (Math.sqrt(r) - 2) * Math.pow(scale, -i);
}


Title: Re: A Question about the Menger fractal
Post by: claude on May 19, 2016, 02:17:58 PM
Hi!

Here's a DE function implemented in GLSL for a cube made out of the intersection of 6 planes:


Code:
float plane(vec3 normal, float d, vec3 p) {
  return dot(normal, p) - d;
}

float cube(vec3 p) {
return max(max(max(max(max(
  plane(vec3(1, 0, 0), 1, p),
  plane(vec3(-1, 0, 0), 1, p)),
  plane(vec3(0, 1, 0), 1, p)),
  plane(vec3(0, -1, 0), 1, p)),
  plane(vec3(0, 0, 1), 1, p)),
  plane(vec3(0, 0, -1), 1, p));
}

This should replace your "dist = (Math.sqrt(...)-2)".  Might need some tweaks for cube size and origin.  Your  current dist is for a sphere.


Title: Re: A Question about the Menger fractal
Post by: Imagyx on May 19, 2016, 04:11:51 PM
Thank you claude  :)
This means cutting the spheres which were there by 6 planes,leaving cubes behind,  right ?
It looks fine for the first two but gets really noisy with higher iteration counts and I don't know why.
I cannot tweak it with threshold or number of raysteps...
Cube size and origin seem fine. So what else could be the problem there ?


Title: Re: A Question about the Menger fractal
Post by: claude on May 19, 2016, 06:18:16 PM
It's more replacing the spheres with cubes rather than cutting.

The noise looks like aliasing from the high-frequency content, try supersampling (or rendering bigger and downscaling).


Title: Re: A Question about the Menger fractal
Post by: Imagyx on May 20, 2016, 10:24:14 AM
Im not sure if there's not still something wrong in the process itself, anything I need to change in the code...
Because if you look at the second image in the lower center, therefore a place nearest to the camera,
there's some noise as well, that isn't appearing in the left, right or top parts of the "sponge".
I'll experiment a bit more, hopefully with better results  :dink: