Calculate random points (pixel) within a circle (image)

Posted by DMills on Game Development See other posts from Game Development or by DMills
Published on 2012-04-03T20:11:33Z Indexed on 2012/04/03 23:42 UTC
Read the original article Hit count: 136

Filed under:
|

I have an image that contains a circles at a specific location, and of a specific diameter. What I need to do is to be able to calculate random points within the circle, and then manipulate said the pixels they correlate to. I have the following code already:

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

And that works fine for finding all the points at the circumference of the circle, but I need all points from anywhere in the circle. If this doesn't make sense let me know and I will do my best to clarify.

© Game Development or respective owner

Related posts about c#

Related posts about algorithm