|
![](/i/fill.gif) |
"mine" <nomail@nomail> wrote in message
news:web.44687a797f9206dfa533cc200@news.povray.org...
> I've made a basic macro (with the help of a tutorial)that randomly places
> objects (in this case spheres) in a given space. The trouble is the
> tutorial didn't tell me how to stop the spheres from touching. Can anyone
> help? I've included the macro below.
>
> #declare floater = sphere{<0,.5,0>, 1}
> #declare thingy_red = <1,0,0>;
> #declare floater_count = 20;
> #declare Locations = seed(1);
> #while (floater_count > 0)
> #declare x_loc = rand(Locations)*7-1;
> #declare y_loc = rand(Locations)*7-1;
> #declare z_loc = rand(Locations)*7-1;
> object{floater
> pigment{color thingy_red}
> translate <x_loc,y_loc,z_loc>
> }
> #declare floater_count = floater_count - 1;
> #end
>
>
Hi,
You can declare an array of size 'floater_count', then each time round the
current loop, do another loop to test whether the position of the centre of
the sphere is closer than the diameter of floater to any of the existing
positions (see the vlength() function, which you can use on the difference
between each pair of positions).
Then you can put the 'object' statement plus the line where you decrement
'floater_count' inside an #if clause along with a new line to add the new
position into the array.
If you're likely to want to increase float_count to where you get close to
the limit where you can't find enough positions, then you should also add a
way of breaking out of your existing loop to avoid that you loop
indefinitely.
I didn't post code because it sounds like you're trying to work stuff out
for yourself, but if you want the answer, just say.
Regards,
Chris B.
Post a reply to this message
|
![](/i/fill.gif) |