我试图在Python中找到两个圆之间的交点(使用Matplotlib),但无法获得任何值。
为此,我为每个单独的圆创建了X和Y的列表(当绘制圆时,Matplotlib将第一个参数作为X值,第二个参数作为Y值),然后相应地将列表相交(例如,circle1 x值与circle2 x值)。
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)))
我希望得到返回值,但是返回的集合是空的。
https://stackoverflow.com/questions/55816902
复制相似问题