2

I am trying to use a boost random generator to make random points uniformly distributed over a plane surface. I have the following link for doing it in a single dimension:

Here they use boost::uniform_int<> to generate numbers as int in a single dimension.

But in my case I wish to generate numbers as float in two dimensions over a plane.

Is there any distribution type available to use it in two dimensions? (I have seen boost::uniform_on_sphere, but it is for spherical surfaces.)

Community
  • 1
  • 1
sekaran
  • 31
  • 6

2 Answers2

0

Use the uniform_01 distribution and generate two random numbers, giving you the x and y coordinates. Scale accordingly :)

filmor
  • 30,840
  • 6
  • 50
  • 48
  • Do you mean like this to declare one for x and other for y axis: boost::uniform_01<> for_x_axis (0,2); boost::uniform_01<> for_y_axis (0,4); – sekaran Jan 25 '13 at 13:24
  • I was under the impression that `uniform_01` would just generate elements in the interval `[0,1)` (which might be important!), so you'd take one distribution and multiply the two values you get by the scaling factors. You also don't need Boost for this, a very similar library is available in C++11 in ``. – filmor Jan 25 '13 at 13:32
  • `std::uniform_real_distribution` indeed takes two parameters. – filmor Jan 25 '13 at 13:33
  • but i didn't get it can you please define me an example? – sekaran Jan 25 '13 at 13:59
  • i think they take only maximum and minimum number – sekaran Jan 25 '13 at 16:18
  • the numbers generated by these distributions are uniform_real_distribution : [min..max) and uniform_01 : [0..1). i hope this helps – O.C. Jan 29 '13 at 09:24
0

If x follows uniform distribution 0 to a and y follows uniform distribution 0 to b then points (x, y) are uniformly distributed over the rectangle (0,0)-(a,b) without any special approaches. Just generate the two random numbers rather than one.

These would be required to distribute them differently, at the edge of the circle, for instance (as you talk about the sphere).

Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
  • Is it like two random numbers seperately with the same class boost::uniform_int? – sekaran Jan 25 '13 at 13:59
  • Like any two random numbers, regardless of they generation algorithm as far as it is a uniform distribution algorithm. – Audrius Meškauskas Jan 25 '13 at 15:11
  • let us consider you generate random numbers in x and y axis separately. then combine those values to to form numerous points in a plane. If we do this, the independent uniform distributions would be fine. But the combined one would not be in uniform distributed fashion. Most probably it would change. – sekaran Jan 25 '13 at 15:39