POV-Ray : Newsgroups : povray.advanced-users : Menger Sponge as Isosurface! Server Time
31 Oct 2024 10:20:23 EDT (-0400)
  Menger Sponge as Isosurface! (Message 1 to 5 of 5)  
From: virtualmeet
Subject: Menger Sponge as Isosurface!
Date: 13 Sep 2007 01:30:00
Message: <web.46e8c494ee0a3a9a54585d60@news.povray.org>
Hi all,
I was trying to define the Menger Sponge level 4 as an Isosurface for
visualisation with K3DSurf and this is my best result :
===============================================================
// Menger Sponge Level 4
// Author: Abderrahman Taha (Sep 2007)


#include "stdinc.inc"
#include "arrays.inc"


global_settings {
 assumed_gamma 1
}

sky_sphere {
 pigment {gradient y
  color_map {
   [0 color Blue*0.6]
   [1 color White]
  }
 }
}

#default {finish {ambient 0}}

//----------------------------------------
#declare CamLoc = < 2, 2,-2>;
camera {
 location CamLoc
 look_at <0, 0, 0>
}

light_source {<-20, 30, -30>*3 color White*1.5}
light_source {CamLoc color rgb 0.3}


//----------------------------------------


isosurface {
 function {
             ( pow(x,1000) + pow(y,1000) +pow(z,1000) -1)*
             (
(abs(x) >1/3 | abs(y) > 1/3 ) &( abs(z) >1/3 | abs(y) > 1/3 ) &( abs(x) >1/3
| abs(z) > 1/3 )
&
( (( ( (abs(x-2/3) <1/9) + (abs(x+2/3) <1/9) + (abs(x) <1/9) ) *
((abs(y-2/3) < 1/9) +(abs(y) < 1/9) +(abs(y+2/3) <1/9) + (abs(z-2/3) < 1/9)
+(abs(z) < 1/9) +
(abs(z+2/3) < 1/9))) +( ( (abs(z-2/3) <1/9) + (abs(z+2/3) <1/9) + (abs(z)
<1/9) ) *
( (abs(y-2/3) < 1/9) + (abs(y) < 1/9) + (abs(y+2/3) < 1/9))) ) =0)
&
( (( ( (abs(x-2/3) <1/27)+(abs(x-2/3-2/9) <1/27) + (abs(x-2/3+2/9) <1/27)
+(abs(x+2/3) <1/27) +
(abs(x+2/3-2/9) <1/27) + (abs(x+2/3+2/9) <1/27) +(abs(x) <1/27) +
(abs(x-2/9) <1/27) +
(abs(x+2/9) <1/27)) * ((abs(y-2/3) < 1/27) + (abs(y-2/3-2/9) < 1/27) +
(abs(y-2/3+2/9) < 1/27) +
(abs(y) < 1/27) + (abs(y-2/9) < 1/27) + (abs(y+2/9) < 1/27) + (abs(y+2/3)
<1/27) +
(abs(y+2/3-2/9) <1/27) + (abs(y+2/3+2/9) <1/27) + (abs(z-2/3) < 1/27) +
(abs(z-2/3-2/9) < 1/27) +
(abs(z-2/3+2/9) < 1/27) + (abs(z) < 1/27) + (abs(z-2/9) < 1/27) +
(abs(z+2/9) < 1/27) +
(abs(z+2/3) < 1/27) + (abs(z+2/3-2/9) < 1/27) + (abs(z+2/3+2/9) < 1/27) )) +
( ( (abs(z-2/3) <1/27) + (abs(z-2/3-2/9) <1/27) + (abs(z-2/3+2/9) <1/27) +
(abs(z+2/3) <1/27) +
(abs(z+2/3-2/9) <1/27) + (abs(z+2/3+2/9) <1/27) + (abs(z) <1/27) +
(abs(z-2/9) <1/27) +
(abs(z+2/9) <1/27) ) * ( (abs(y-2/3) < 1/27) + (abs(y-2/3-2/9) < 1/27) +
(abs(y-2/3+2/9) < 1/27) +
(abs(y) < 1/27) + (abs(y-2/9) < 1/27) + (abs(y+2/9) < 1/27) + (abs(y+2/3) <
1/27) +
(abs(y+2/3-2/9) < 1/27) + (abs(y+2/3+2/9) < 1/27)))) =0)
&
( ((
(
(abs(x-2/3) <1/81)+ (abs(x-2/3-2/27) <1/81)+ (abs(x-2/3+2/27) <1/81)+
(abs(x-2/3-2/9) <1/81) + (abs(x-2/3-2/9-2/27) <1/81) + (abs(x-2/3-2/9+2/27)
<1/81) +
(abs(x-2/3+2/9) <1/81) +(abs(x-2/3+2/9-2/27) <1/81) +(abs(x-2/3+2/9+2/27)
<1/81) +
(abs(x+2/3) <1/81) +(abs(x+2/3-2/27) <1/81) +(abs(x+2/3+2/27) <1/81) +
(abs(x+2/3-2/9) <1/81) +(abs(x+2/3-2/9-2/27) <1/81) +(abs(x+2/3-2/9+2/27)
<1/81) +
(abs(x+2/3+2/9) <1/81) +(abs(x+2/3+2/9-2/27) <1/81) +(abs(x+2/3+2/9+2/27)
<1/81) +
(abs(x) <1/81) + (abs(x-2/27) <1/81) +(abs(x+2/27) <1/81) +
(abs(x-2/9) <1/81) + (abs(x-2/9-2/27) <1/81) + (abs(x-2/9+2/27) <1/81) +
(abs(x+2/9) <1/81)+(abs(x+2/9-2/27) <1/81)+(abs(x+2/9+2/27) <1/81)
) *
(
(abs(y-2/3) < 1/81) + (abs(y-2/3-2/27) < 1/81) +(abs(y-2/3+2/27) < 1/81) +
(abs(y-2/3-2/9) < 1/81) + (abs(y-2/3-2/9-2/27) < 1/81) +(abs(y-2/3-2/9+2/27)
< 1/81) +
(abs(y-2/3+2/9) < 1/81) +(abs(y-2/3+2/9-2/27) < 1/81) +(abs(y-2/3+2/9+2/27)
< 1/81) +
(abs(y) < 1/81) + (abs(y-2/27) < 1/81) + (abs(y+2/27) < 1/81) +
(abs(y-2/9) < 1/81) + (abs(y-2/9-2/27) < 1/81) + (abs(y-2/9+2/27) < 1/81) +
(abs(y+2/9) < 1/81) + (abs(y+2/9-2/27) < 1/81) + (abs(y+2/9+2/27) < 1/81) +
(abs(y+2/3) <1/81) + (abs(y+2/3-2/27) <1/81) + (abs(y+2/3+2/27) <1/81) +
(abs(y+2/3-2/9) <1/81) + (abs(y+2/3-2/9-2/27) <1/81) + (abs(y+2/3-2/9+2/27)
<1/81) +
(abs(y+2/3+2/9) <1/81) + (abs(y+2/3+2/9-2/27) <1/81) + (abs(y+2/3+2/9+2/27)
<1/81) +
(abs(z-2/3) < 1/81) + (abs(z-2/3-2/27) < 1/81) + (abs(z-2/3+2/27) < 1/81) +
(abs(z-2/3-2/9) < 1/81) + (abs(z-2/3-2/9-2/27) < 1/81) +
(abs(z-2/3-2/9+2/27) < 1/81) +
(abs(z-2/3+2/9) < 1/81) + (abs(z-2/3+2/9-2/27) < 1/81) +
(abs(z-2/3+2/9+2/27) < 1/81) +
(abs(z) < 1/81) + (abs(z-2/27) < 1/81) + (abs(z+2/27) < 1/81) +
(abs(z-2/9) < 1/81) + (abs(z-2/9-2/27) < 1/81) + (abs(z-2/9+2/27) < 1/81) +
(abs(z+2/9) < 1/81) + (abs(z+2/9-2/27) < 1/81) + (abs(z+2/9+2/27) < 1/81) +
(abs(z+2/3) < 1/81) + (abs(z+2/3-2/27) < 1/81) + (abs(z+2/3+2/27) < 1/81) +
(abs(z+2/3-2/9) < 1/81) + (abs(z+2/3-2/9-2/27) < 1/81) +
(abs(z+2/3-2/9+2/27) < 1/81) +
(abs(z+2/3+2/9) < 1/81) +(abs(z+2/3+2/9-2/27) < 1/81) +(abs(z+2/3+2/9+2/27)
< 1/81)
)) +
(
(
(abs(z-2/3) <1/81) + (abs(z-2/3-2/27) <1/81) + (abs(z-2/3+2/27) <1/81) +
(abs(z-2/3-2/9) <1/81) + (abs(z-2/3-2/9-2/27) <1/81) + (abs(z-2/3-2/9+2/27)
<1/81) +
(abs(z-2/3+2/9) <1/81) + (abs(z-2/3+2/9-2/27) <1/81) + (abs(z-2/3+2/9+2/27)
<1/81) +
(abs(z+2/3) <1/81) + (abs(z+2/3-2/27) <1/81) + (abs(z+2/3+2/27) <1/81) +
(abs(z+2/3-2/9) <1/81) + (abs(z+2/3-2/9-2/27) <1/81) + (abs(z+2/3-2/9+2/27)
<1/81) +
(abs(z+2/3+2/9) <1/81) + (abs(z+2/3+2/9-2/27) <1/81) + (abs(z+2/3+2/9+2/27)
<1/81) +
(abs(z) <1/81) + (abs(z-2/27) <1/81) + (abs(z+2/27) <1/81) +
(abs(z-2/9) <1/81) + (abs(z-2/9-2/27) <1/81) + (abs(z-2/9+2/27) <1/81) +
(abs(z+2/9) <1/81) + (abs(z+2/9-2/27) <1/81) + (abs(z+2/9+2/27) <1/81)
) * (
(abs(y-2/3) < 1/81) + (abs(y-2/3-2/27) < 1/81) + (abs(y-2/3+2/27) < 1/81) +
(abs(y-2/3-2/9) < 1/81) + (abs(y-2/3-2/9-2/27) < 1/81) +
(abs(y-2/3-2/9+2/27) < 1/81) +
(abs(y-2/3+2/9) < 1/81) + (abs(y-2/3+2/9-2/27) < 1/81) +
(abs(y-2/3+2/9+2/27) < 1/81) +
(abs(y) < 1/81) + (abs(y-2/27) < 1/81) + (abs(y+2/27) < 1/81) +
(abs(y-2/9) < 1/81) + (abs(y-2/9-2/27) < 1/81) + (abs(y-2/9+2/27) < 1/81) +
(abs(y+2/9) < 1/81) + (abs(y+2/9-2/27) < 1/81) + (abs(y+2/9+2/27) < 1/81) +
(abs(y+2/3) < 1/81) + (abs(y+2/3-2/27) < 1/81) + (abs(y+2/3+2/27) < 1/81) +
(abs(y+2/3-2/9) < 1/81) + (abs(y+2/3-2/9-2/27) < 1/81) +
(abs(y+2/3-2/9+2/27) < 1/81) +
(abs(y+2/3+2/9) < 1/81) + (abs(y+2/3+2/9-2/27) < 1/81) +
(abs(y+2/3+2/9+2/27) < 1/81)
)
)) =0)
 )


 }
 threshold 0
 max_gradient 5
 texture {
  pigment {color rgb < 0.3, 0.85, 0.4>}
  normal {bozo 0.1 scale < 1, 0.15, 1>}
 }
}
=================================================================

By googling I found that there is a Pov-Ray script that describe the Menger
Sponge as an isosurface but I can't locate it. I'm looking for it because
I'm interested in the isosurface formula that was used and want to compare
it to my own result. If you've any infos please let me know.
Cheers,
Taha
PS: Menger Sponge Code for K3DSurf and screen shots can be found here :
http://k3dsurf.s4.bizhat.com/viewtopic.php?t=61&mforum=k3dsurf


Post a reply to this message

From: Karl Anders
Subject: Re: Menger Sponge as Isosurface!
Date: 14 Sep 2007 02:50:00
Message: <web.46ea2df49b9aa03b307086da0@news.povray.org>
Hi,

there are (at least) two solutions I know of to define THE SPONGE as an
isosurface recursively(!)

One by David Wallace, who published the source here:
http://www-inst.eecs.berkeley.edu/~dtw/pov/misc/_povsrc/iso_menger.pov
( the interesting part is at the end of the file )

The other one is here:
http://pcharpen.club.fr/pov/menger.pov
and is IMHO less easy to understand, not only because it's french :-)

Have fun, happy tracing

Karl


Post a reply to this message

From: virtualmeet
Subject: Re: Menger Sponge as Isosurface!
Date: 15 Sep 2007 01:40:00
Message: <web.46eb6ede9b9aa03b8e7081c20@news.povray.org>
"Karl Anders" <kar### [at] webde> wrote:
> there are (at least) two solutions I know of to define THE SPONGE as an
> isosurface recursively(!)
Hi Karl,
First thanks for the links :). The link to the David Wallace page was the
one I was looking for. Unfortunately both PovRay scripts are using
recursivity which I'm trying to avoid in my own example. in short, I'm
looking for a way (giving a level N) to define the Menger Sponge without
using recursivity or a way to shrink the formula above. Recursivity is not
the best way to understand how things work not to mention that it's usually
slower and less memory efficient...
So, I'm still looking for a super-compact formula that can say (giving a
level N)  if a 3D point is "in" or "out" of a Menger Sponge volume.
Cheers,
Taha


Post a reply to this message

From: Matt Denham
Subject: Re: Menger Sponge as Isosurface!
Date: 30 Sep 2007 00:55:01
Message: <web.46ff2b089b9aa03b15a330d40@news.povray.org>
"virtualmeet" <tah### [at] yahoofr> wrote:
> "Karl Anders" <kar### [at] webde> wrote:
> > there are (at least) two solutions I know of to define THE SPONGE as an
> > isosurface recursively(!)
> Hi Karl,
> First thanks for the links :). The link to the David Wallace page was the
> one I was looking for. Unfortunately both PovRay scripts are using
> recursivity which I'm trying to avoid in my own example. in short, I'm
> looking for a way (giving a level N) to define the Menger Sponge without
> using recursivity or a way to shrink the formula above. Recursivity is not
> the best way to understand how things work not to mention that it's usually
> slower and less memory efficient...
> So, I'm still looking for a super-compact formula that can say (giving a
> level N)  if a 3D point is "in" or "out" of a Menger Sponge volume.
> Cheers,
> Taha

Well...  the simplest method requires producing the base-3 expansion of the
number, and any point with a 1 in that expansion isn't in the Sponge.

Unfortunately, base conversions are invariably recursive, and work as
follows (in general form):

Given a starting number N, begin by taking P = int(log(N)/log(B)).  (This
gives your starting place in base B.)
While N is non-zero, do the following:
* Take D = int(N/pow(B,P));
* Write that down as the next digit;
* Change N = N - D * pow(B,P);
* Change P = P - 1;
* If P = -1, write down a "decimal" point.

If you write this algorithm out to produce a string, you then have to scan
that string for a 1 in it (which, considering the lack of "where in a given
string is the first occurrence of this character" functions in POV-Ray's
SDL, requires a second macro of its own, though it's a relatively simple
one).

Net result: there is not both a compact and non-recursive formula for the
Menger Sponge or similar objects.


Post a reply to this message

From: honnza
Subject: Re: Menger Sponge as Isosurface!
Date: 6 Oct 2007 06:40:00
Message: <web.470765c39b9aa03ba9ce4df50@news.povray.org>
Hi,
try this:

#declare mid=function(x,y,z){min(max(x,y),max(x,z),max(y,z))}
#declare maxlevel=5;//set to what you like
#declare level=0;
#while(level<maxlevel)
  Parse_String(concat("#declare sponge",str(level,0,0)))=function(x,y,z){
    select(
      (l&mid(abs(x),abs(y),abs(z))>1/3)-0.5
    ,
      mid(abs(x),abs(y),abs(z))-1/3
    ,

Parse_String(concat("sponge",str(level,0,0)))(abs(3*x)-2,abs(3*y)-2,abs(3*z)-2)
    )
  }
  #set l=l+1;
#end
isosurface{
  function{concat("sponge",str(maxlevel,0,0))(x,y,z)}
  material{m_concrete}
  scale 5
}


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.