Get the whole pixel array inside the circle

I have it:

enter image description here

And I need to know all the pixels in the array inside the circle.

Thank.

+5
source share
1 answer

You are looking for the following set of pixels:

Circle equation

where r is the radius of your circle and (m1, m2) is the center.

In order for these pixels to move over all positions and save those that match the criteria in the list:

List<int> indices = new List<int>();

for (int x = 0; x < width; x++)
{
    for (int y = 0; y < height; y++)
    {
        double dx = x - m1;
        double dy = y - m2;
        double distanceSquared = dx * dx + dy * dy;

        if (distanceSquared <= radiusSquared)
        {
            indices.Add(x + y * width);
        }
    }
}
+12
source

All Articles