Search for all points common to two circles

In Python, how would I find all the integer points common to two circles?

For example, imagine a Venn diagram intersecting two (same sized) circles with centers (x1,y1)and (x2,y2)and radii r1=r2. In addition, we already know that the two points of intersection of circles (xi1,yi1)and (xi2,yi2).

How would you effectively create a list of all the points (x,y)contained in both circles? That is, it would be simple to draw a field containing the intersections and scroll through it, checking if the given point is in both circles, but is there a better way?

+5
source share
6 answers

, .

  • , , " " .
  • , , " " - / . , , , , .
  • .
  • "" , . , . , , , . , , .
+1

, . , , .

+1

, , .

, , . , , ,

r1 + r2 - D

D . , X Y. ( , !)

. , . .

+1

. , , .

, x, y, , , x, y ( )

, , , . , , .

x y, , .

+1

, , ?

, , . , , .

, , .

0

, " " " ". , NX NY .

int x0[NY], x1[NY]; initially full of -1.

, . x, y . y ( , y + 0,5), x . x0 [y] -1, x0, x1.

Also keep track of the lowest and highest y values.

When you're done, just iterate over y and on each y, iterate over x between x0 and x1, i.e. for (ix = x0[iy]; ix < x1[iy]; ix++)(or vice versa).

It is important to understand that pixels are not points where x and y are integers. Rather, pixels are small squares between grid lines. This will prevent edge issues.

0
source

All Articles