def find2Points(circle_1, circle_2):
x_1 = circle_2[0] - circle_1[0]
y_1 = circle_2[1] - circle_1[1]
r_0 = circle_1[2]
r_1 = circle_2[2]
a = -2 * x_1
b = -2 * y_1
c = x_1 ** 2 + y_1 ** 2 + r_0 ** 2 - r_1 ** 2
x_2 = -(a * c) / (a ** 2 + b ** 2)
y_2 = -(b * c) / (a ** 2 + b ** 2)
distance = (x_2 ** 2 + y_2 ** 2) ** (0.5)
if distance > circle_1[2]:
coords = ['error']
elif distance == circle_1[2]:
coords = [x_2 + circle_1[0], y_2 + circle_1[1]]
else:
d = (r_0 ** 2 -(c ** 2) / (a ** 2 + b ** 2)) ** (0.5)
tmp = ((d ** 2) / (a ** 2 + b ** 2)) ** (0.5)
x_p1 = x_2 + b * tmp
y_p1 = y_2 - a * tmp
x_p2 = x_2 - b * tmp
y_p2 = y_2 + a * tmp
coords = [[x_p1 + circle_1[0], y_p1 + circle_1[1]], [x_p2 + circle_1[0], y_p2 + circle_1[1]]]
return coords
def sortRectangle(a, b, c, d):
tmp = []
delta = 0.000000001
coords = find2Points(a, b)
tmp += coords
if len(tmp) > 1:
coords = find2Points(a, c)
for coord in coords:
for coord_tmp in tmp:
if (coord[0] - coord_tmp[0]) ** 2 + (coord[1] - coord_tmp[1]) ** 2 < delta:
return coord
else:
return tmp
a = [-3, 2, 5]
b = [3, 2, 5]
c = [3, -2, 3]
d = [-3, -2, 3]
print(sortRectangle(a, b, c, d))