Context
I need to measure the area of combined circles in python. I came up with way using numpy arrays. First, I populate a grid (numpy array) with zeros, each position in the grid corresponds to a length of 0.5cm. I then drop the centre of the circle onto the grid and change this value to 1 in the grid. I know the radius of the circles so I can calculate the area of the circle, because I know the area of the circle I change the the zeros in the grid to which fall in the area of the circle ones. I then count the frequency of ones in the gird and use this to calculate the area of the combined circles, because I know the length of each position in the grid I can calculate the area. This is currently a very coarse grain method, I plan to change it to a finer grain once I have the algorithm nailed down.
Example
If you look at the image I posted below which describes my idea better. There are two circles on my grid (red lines), the centre of the circles are marked with a blue square and the area the circles occupy are in a light orange. I want to change the the area with marked with orange to ones. I can currently change the the orange squares horizontal and vertical to the circle centre, but the diagonal boxes from the centre are causing me trouble.
Current code
class area():
def make_grid(self):
'''
Each square in the grid represents 0.5 cm
'''
import numpy as np
grid = np.zeros((10,10))
square_length = 0.5
circles = {'c1':[[4,2],1.5],'c2':[[5,6],2.0]}
print grid
for key,val in circles.iteritems():
grid[val[0][0]][val[0][1]] = 1
area = int((val[1] - square_length)/0.5)
for i in xrange(1,area+1):
grid[val[0][0]][val[0][1]+i] = 1 # Change column vals in +ve direction
grid[val[0][0]][val[0][1]-i] = 1 # Chnage column vals in -ve direction
grid[val[0][0]+i][val[0][1]] = 1 # Chnage row vals in +ve direction
grid[val[0][0]-i][val[0][1]] = 1 # Chnage row vals in -ve direction
print ''
print grid
In the dictionary above, the key is the circle name, the first element in the value is the circle centre co-ordinates and the second element is the radius of the circle.
The code outputs:
[[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 1. 0. 0. 0. 1. 0. 0. 0.]
[ 0. 0. 1. 0. 0. 0. 1. 0. 0. 0.]
[ 1. 1. 1. 1. 1. 0. 1. 0. 0. 0.]
[ 0. 0. 1. 1. 1. 1. 1. 1. 1. 1.]
[ 0. 0. 1. 0. 0. 0. 1. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 1. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 1. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]