|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
|
|