Reputation: 1
I know how to get a random point within a rectangle, But know I need to know how to get a random point that will have more of a chance of getting selected if it is near the center. It should be some form of exponential equation, but I can not figure it out.
Does anyone have any ideas?
Upvotes: 0
Views: 223
Reputation: 4481
Are you mean normal distribution over polar coordinates with center of the rectangle center?
Upvotes: 0
Reputation: 879
It sounds like you are trying to calculate something like bullet-spread in a game.
Since you know the rectangle that you want all of the hits generated in, you also know the center of that rectangle.
I would recommend that you calculate a random value for both the horizontal and vertical offsets from this point. By applying a function to the random values you are getting, you can shape them to appear more clustered.
I don't know if performance is a tight concern for you, but the square root is one such function you could apply to cluster your values closer to zero. Other alternatives include curves such as y = ln(x).
Upvotes: 1
Reputation: 1788
consider your random values as polar coordinates, instead of cartesian.
Upvotes: 0