This post includes a scene file in response to a question on povray.newusers
about randomly distributing pieces of cereal around in a surface (milk in
this case). It stacks up bits of cereal, checking that the pieces don't
intersect.
It uses the rand() function to move a torus away from the origin. It then
uses it again to rotate it so that the pieces of cereal are distributed
randomly in a disc.
The tricky bit is detecting and avoiding collisions. This example uses a
combination of a number of principles gleaned from these news groups in the
past. It checks each new piece of cereal against all previously defined
pieces of cereal by doing an intersection and measuring the size of the
result. Unfortunately this isn't very accurate (at least in POVRay 3.5 that
I'm using) and therefore the example also steps through the points between
the minimum extent of the intersection object and the maximum extent of the
intersection object, looking for points that are inside the intersection
object. If it finds a collision it moves the new piece of cereal to
somewhere else and checks that position for collisions until it finds
somewhere where it doesn't intersect with anything else.
This gets exponentially more expensive on machine resource as you increase
the number of objects.
Hope this is useful
Chris B.
Post a reply to this message
Attachments:
Download 'cereal.pov.txt' (3 KB)
|