I'm trying to find the intersections between two circles in Python(using Matplotlib) but can't get any values back.
I'm doing this by creating lists of X's and Y's for each individual circle(Matplotlib takes the first argument as X values and the second one as Y values when drawing a circle), and then intersecting the lists accordingly(e.g., circle1 x values with circle2 x values).
import numpy
import math
import matplotlib.pyplot as plt
import random
def origin_circle():
global x_points
global y_points
global r
global n
r=1
n=2**16
x_points=[(r*math.cos(t)) for t in numpy.linspace(0, 2*numpy.pi*r, n+1)]
y_points=[(r*math.sin(t)) for t in numpy.linspace(0, 2*numpy.pi*r, n+1)]
def new_circle(x_offset, y_offset):
global x_points1
global y_points1
x_points1=[x_offset+(r*math.cos(t)) for t in numpy.linspace(0, 2*numpy.pi*r, n+1)]
y_points1=[y_offset+(r*math.sin(t)) for t in numpy.linspace(0, 2*numpy.pi*r, n+1)]
origin_circle()
new_center= random.randint(0, len(x_points))
x_offset = x_points[new_center]
y_offset = y_points[new_center]
new_circle(x_offset, y_offset)
print(set(x_points1).intersection(set(x_points)))
print(set(y_points1).intersection(set(y_points)))
I expected to get values back, but the set that returned was empty.
(set(x_points1).intersection(set(x_points)))
will practically never find an intersection between these two sets, just points that happen to exist in both sets. Since you are generating points around the outside of each circle it is extremely unlikely that two of these points will be exactly the same on different circles, even being off by0.00000000001
will ensure that your intersection finds nothing. You'll need a better method for finding the intersection. – Mendel