Skip to main content
2 of 4
added 592 characters in body
David Gouveia
  • 25k
  • 5
  • 88
  • 127

If you want a simple solution just randomize the radius too:

private Point CalculatePoint()
{
    var angle = _random.NextDouble() * Math.PI * 2;
    var radius = _random.NextDouble() * _radius;
    var x = _originX + radius * Math.Cos(angle);
    var y = _originY + radius * Math.Sin(angle);
    return new Point((int)x,(int)y);
}

That however results in your points being more concentrated in the center of the circle:

enter image description here

In order to have a more uniform distribution, there's a small tweak you can make to the algorithm:

var radius = Math.Sqrt(_random.NextDouble()) * _radius;

With this change, your distribution will become like the following image, which is probably preferrable:

enter image description here

Source of this information: MathWorld - Disk Point Picking.

David Gouveia
  • 25k
  • 5
  • 88
  • 127