[Closed] scatter script without intersections
hi,
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…
simplyfying…
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.
b
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.”
- Neil
thanks neil,
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:
b
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.
- Neil