View Full Version : scatter script without intersections
03-24-2006, 04:51 AM
i was wondering how the code would look like if i had to scatter a few objects(box for e.g) in a certain volume without intersecting each other.
could someone please spot me here...
1.generate a random() and collect it in an array.
2.iterate thorugh each element in the array and see if there are no repeats.
3.assign the values to the objects.
i'd be ok with a c type syntax too.
thanks for any pointers.
03-24-2006, 02:28 PM
Well, it's more complex than that, because you have to take into account the dimensions of the box. So what you'd need to do is...
- pick a point, define your volume
- pick a new random point, define your second volume
- test to see if the first volume and second volume intersect. If they do, throw out your second volume and try again. If not, move onto a third volume.
Oh, and make sure you program in a stopping condition of some kind, just in case your algorithm can't find a new box to place that doesn't intersect with one of the previous boxes. So something like "if the script errors out more than x times, end the script."
03-29-2006, 11:17 AM
in c++ there's a method called shuffling.
so i'd fill an array with a set of numbers thus circumventing the repeat problem which could crop up in the random method.
Then use the shuffle method to assign the axes of each object.
i wonder how much of apain in the ass it'd b if the volumes of the boxes would change too. :wip:
03-29-2006, 02:54 PM
In still think it will be more complex than that, since you'll need a max and min x value, max and min y value, etc, all of which does not intersect. And then there's the standard problem of trying to fill a small volume with a large set of objects. Not that I'm an expert in this area, but I do believe it's quite involved.
03-29-2006, 02:54 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.