views:

83

answers:

1

Hello:

I would like to generate random points on a 3D box defined by its (minx, miny, minz) and (maxx, maxy, maxz) corners. I was thinking of generating a random point inside of the box and then somehow projecting it onto one of the box sides. However, I don't have explicit plane information for the box sides and this seems like it will not produce a uniform distribution of points since if some sides of the box are bigger than others, those sides should have more points generated on them.

Any suggestions are appreciated.

Thanks.

+3  A: 
  1. Select a side at random weighted by it's area (spare link or this one ...)
  2. Place a point randomly selected from a uniform distribution on that side
  3. Lather, rinse, repeat.

or alternately

  1. Decide on the density of points
  2. Populate each side in turn with a random set of points having that density

which is more uniform (i.e. less random) but will look fine as long as the density is high enough for each side to have more than a handful of points

dmckee
Thanks for the help. This seems to generate points on the faces of the box, ignoring edges and vertices. Any tips on how I can incorporate edges and vertices?
Myx
@Myx: "On" the edges and vertices makes up very little of the available area (infinitesimal in the limit of real points, but finite for "dots"), so a random scattering won't hit them much. Make sure that you are generating across the *inclusive* limits of the figure. That is make sure that if the length is `l`, both `0` and `l` are admitted in the PRNG. If you *really* want to outline the figure, throw "on edge" points separately. For that you'll need a different density.
dmckee
for some reason when I implement the scheme, the points are being randomly generated on 4 of the sides but on 2 of them (they are also opposite sides, i.e. top and bottom), the points are only being generated from the center of the face and up along the normal. Any idea what could be going wrong?
Myx
If it was my code I would suspect an *Error Between Keyboard and Chair*. Look closely at the logic you use setting the random limits for those faces. (Given that you have a rectangular solid I assume you're using the same code for both, right?) Trace the execution if you have to (debugger or by hand).
dmckee