POV-Ray : Newsgroups : povray.advanced-users : Menger Sponge as Isosurface! : Re: Menger Sponge as Isosurface! Server Time
8 Jul 2024 19:52:52 EDT (-0400)
  Re: Menger Sponge as Isosurface!  
From: Matt Denham
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

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