POV-Ray : Newsgroups : povray.general : Stacking Balls : Re: Stacking Balls Server Time
13 Aug 2024 19:21:34 EDT (-0400)
  Re: Stacking Balls  
From: Lance Birch
Date: 25 Aug 1998 09:37:56
Message: <35e2b024.0@news.povray.org>
You're talking about SUDS right?  What you do is this:

Create an array which holds position values and radii for the spheres (one
entry for each sphere).  Then as you create each new sphere test it against
all previously created spheres to make sure it doesn't touch.  If it doesn't
touch add it, if it does, discard it and try another one.

In Psuedo-Code:

for noofspheres = 0 to 1000

NextRandomSphere:

x1 = rand * 100
y1 = rand * 100
z1 = rand * 100
rad1 = rand * 3

passed = 0

    for csphere = 0 to upperbound of sphereset

        x2 = sphereset(csphere).x
        y2 = sphereset(csphere).y
        z2 = sphereset(csphere).z
        rad2 = sphereset(csphere).r

        d = sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2)

        if d > rad1+rad2 then
            passed = passed + 1
        endif

    next csphere

if passed = 0 then
    redimension sphereset (upperbound of sphereset + 1) preserve
    sphereset(upperbound of sphereset).x = x1
    sphereset(upperbound of sphereset).y = y1
    sphereset(upperbound of sphereset).z = z1
    sphereset(upperbound of sphereset).r = rad1
else
    go back to NextRandomSphere
endif

next noofspheres

This will create an array of 1000 positions and radii of spheres that are
not neccessarily tangential (or though I'm sure you could do that easily
enough, i.e. modify the creation of the xyz and radius to be tangential to a
randomly selected sphere from the array) but don't touch.

Should work, haven't tested it though.  I did this once with candles of
different heights and radii to create a 'floor' full of lit candles.  Looked
really cool, took AGES to render.  Have fun.

--
Lance Birch
http://come.to/the.zone
Remove the smiley to e-mail.


Post a reply to this message

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