But the code is too slow.
Your algorithm is quadratic in radius. Using the smaller of the two radii will not change this. In the worst case, one circle in another lies, therefore the number of points in the intersection is equal to the number of points in the smaller circle. The number of points lying on the coordinate grid inside the circle is proportional to the area of the circle, that is, ~ r 2 . Therefore, any method in which points one by one are considered to be quadratic, that is, it leads to ~ 10 12 operations in this case (slowly).
You can use a linear algorithm to improve efficiency for large radii. At the end of the answer by reference, a detailed explanation of why a quadratic algorithm is much worse than a linear one (for large radii).
To obtain a linear algorithm, you can bypass only one coordinate (for example, vertically along y ), and calculate the number of points (horizontal) at the intersection immediately, determining the intersection of the intervals bounded by given circles:
from math import ceil, floor def count_lattice_points_intersection(a, b): count = 0 for y in range(ay - ar, ay + ar + 1): # scan from bottom to top if by - br <= y <= by + br: # intersection is possible # find intersection boundaries for given y ax1, ax2 = x_coordinates_intesect(a, y) bx1, bx2 = x_coordinates_intesect(b, y) if min(ax2, bx2) >= max(ax1, bx1): # intersect count += floor(min(ax2, bx2)) - ceil(max(ax1, bx1)) + 1 return count def x_coordinates_intesect(c, y): """Get x-coordinates of intersection of circle *c* and horizontal line *y*.""" # solve quadratic equation # (x - cx)**2 + (y - cy)**2 == cr**2 assert cr**2 >= (y - cy)**2 D = (cr**2 - (y - cy)**2)**.5 return cx - D, cx + D
The boundaries of the intervals are solved by solving a quadratic equation for a circle:
(x - cx)**2 + (y - cy)**2 == cr**2
Example :

from collections import namedtuple Circle = namedtuple('Circle', 'x, y, r') print(count_lattice_points_intersection(Circle(0, 0, 5), Circle(2, 2, 3))) # -> 26
26 points of the coordinate lattice are inside the given circles.