Reputation: 1075
I need a method where I can provide a Vector2 location and a radius, which will give me a random point in the radius, with higher chance towards the center than the edge of the radius.
I have tried to search for a solution for this problem but have not been able to decribe the problem well enough in searchengines to come up with a good result.
Hope someone here can point me in the right direction. A code example in any language is highly appreciated!
Upvotes: 1
Views: 128
Reputation: 99172
How about this:
Upvotes: 2
Reputation: 777
Not sure if that's exactly what you want, but it should give you some distribution with more points per volume in the center of the sphere:
You can use this simple formula to find a random evenly distributed point on a spheres surfaces: Generate a random sample of points distributed on the surface of a unit sphere
When you take this point and move it inwards by multiplying it with a random value and dividing by r:
(x,y,z) *= randomValue
where (x,y,z) is the vector pointing at the random point on the surface and randomValue is some random value between 0 and 1.
This gives an even distribution with respect to r, but since the surface are gets smaller with smaller radius, your points will concentrate in the middle.
If you want to further tweak the distribution, you can add some power to randomValue:
(x,y,z) *= pow(randomValue, exponent)
where the higher the exponent, the more points you will get in the middle of the sphere.
Upvotes: 1