POV-Ray : Newsgroups : povray.newusers : Is there a better way of achieving this simple thing Server Time
26 Dec 2024 10:15:10 EST (-0500)
  Is there a better way of achieving this simple thing (Message 1 to 4 of 4)  
From: Elija
Subject: Is there a better way of achieving this simple thing
Date: 14 Apr 2007 07:25:01
Message: <web.4620b972335b34117fd315660@news.povray.org>
I have just downloaded POV-RAY and and am having my first real go at it.

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

=====================================================================

#include "colors.inc"
#include "metals.inc"


camera {
 location <0, 10, -15>
 look_at  <0, 0,  0>
}

light_source { <2, 14, -23> color White}

#declare s = 5;
union {
 #declare l = 0;
 #while (l < s)
  union {
   #declare xco = 0;
   #declare zco = 0;
   #while (zco < s - l)
    union {
     #while (xco < 5 - l)
      sphere {
       <0, 0, 0>, 1
       texture {
        T_Chrome_5E
       }
       translate x * 2 * xco
      }
      #declare xco = xco + 1;
     #end
     translate -4 * x
     translate 2 * zco * z
     #declare xco = 0;
     #declare zco = zco + 1;

    }
   #end
   translate y * (l * 1.25)
   translate x * l
   translate z * l
   #declare l = l + 1;
  }
 #end
 translate -4 * x
}


plane {
 <0, 1, 0>, -1
 pigment {
  checker color Red, color Blue
 }
}

=====================================================================

Thanks for any pointers


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Is there a better way of achieving this simple thing
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

From: Elija
Subject: Re: Is there a better way of achieving this simple thing
Date: 14 Apr 2007 10:30:01
Message: <web.4620e5363ad8003d7fd315660@news.povray.org>
Thanks for the advice. Maybe its because I'm a beginner, but I find
sphere {<0,0,0>,1} much easier to read. The 1.25 was a guess - but it
was exactly what I wanted - how lucky is that?

Anyway that code was the beginnings of my first piccy which I have posted
here for the amusement of all :D

http://news.povray.org/povray.binaries.images/thread/%3Cweb.4620e373f1b9d0837fd315660%40news.povray.org%3E/


Christian Froeschlin <chr### [at] chrfrde> wrote:
> 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

From: Tim Attwood
Subject: Re: Is there a better way of achieving this simple thing
Date: 14 Apr 2007 23:55:12
Message: <4621a220$1@news.povray.org>
> Is there a better way than this of achieving the pyramid of spheres?

I would probably do something like...

#include "handy.inc"

#macro Sphere_Pyramid(Layers, Rad)
   #local S=sphere{<0,0,0>,Rad};
   #local A=Layers;
   #while (A>0)
      GridOf(S,<-A*Rad+Rad,(Layers-A)*1.41*Rad+Rad,-A*Rad+Rad>,
             <0,0,2*Rad>,<2*Rad,0,0>,A,A)
   #local A=A-1;
   #end
#end

union{ Sphere_Pyramid(8,0.25)
   translate <0,-1,0>
   pigment{Silver}
   rotate <0,60,0>
}

Where the #include "handy.inc" has some macros I re-use often.
That way next time I feel like tracing a grid of something I don't
have to re-write the code...

// a grid of object starting at a location and repeating at IncPos and 
IncPos2
#macro GridOf(Obj StartPos IncPos IncPos2 Num Num2)
  #local _COUNT2 = 0;
  #local _CPOS2 = StartPos;
  #while (_COUNT2 < Num2)
    #local _COUNT = 0;
    #local _CPOS = _CPOS2;
    #while (_COUNT < Num)
      object {Obj translate _CPOS}
      #local _CPOS = _CPOS + IncPos;
      #local _COUNT = _COUNT + 1;
    #end
    #local _CPOS2 = _CPOS2 + IncPos2;
    #local _COUNT2 = _COUNT2 + 1;
  #end
#end


Post a reply to this message

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