POV-Ray : Newsgroups : povray.newusers : Is there a better way of achieving this simple thing : Re: Is there a better way of achieving this simple thing Server Time
29 Jul 2024 00:29:33 EDT (-0400)
  Re: Is there a better way of achieving this simple thing  
From: Christian Froeschlin
Date: 14 Apr 2007 09:46:35
Message: <4620db3b$1@news.povray.org>
Elija wrote:

> Is there a better way than this of achieving the pyramid of spheres?

Well, you'll have to build it yourself anyway and you seem to be doing
quite fine, except I think you arrived at "1.25" by trial and error;
the mathematically correct value would be sqrt(2). Also, you can
apply the texture to the outer union if all spheres are identical.

As matter of style, you only need one line setting "xco = 0"
if you do it directly before "#while (xco ...)", you can
replace sphere {<0,0,0>,1} by sphere {0,1} and the
double translate by "translate <-4,0,2*zco>".

Here's a sphere pyramid macro I wrote recently:

#macro sphere_grid(n)
union
{
   #local i = 0;
   #while (i < n)
     #local j = 0;
     #while (j < n)
       sphere {<i,0,j>,0.5}
       #local j = j + 1;
     #end
     #local i = i + 1;
   #end
}
#end

#macro sphere_pyramid(n)
union
{
   #local level = 0;
   #while (level < n)
     object
     {
       sphere_grid(n-level)
       translate <0.5*level,level/sqrt(2),0.5*level>
     }
     #local level = level + 1;
   #end
   translate -(n-1)/2*<1,0,1>
}
#end

It was for the following image:

http://news.povray.org/povray.binaries.images/thread/%3C45c7ba1e@news.povray.org%3E/?ttop=240388&toff=50&mtop=239611&moff=10


Post a reply to this message

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