代码:
import cv2
import numpy as np
from sympy import Point, Circle, Line, var, Symbol
import matplotlib.pyplot as plt
t=Symbol('x')
c1 = Circle(Point(350,300),18)
c2 = Circle(Point(20, 50), 16)
l1 = Line(c1.center, c2.center)
p1 = l1.arbitrary_point(t).subs({t: -c1.radius / (c2.radius - c1.radius+1e-5)})
p2 = l1.arbitrary_point(t).subs({t: c1.radius / (c1.radius + c2.radius+1e-5)})
t1 = c1.tangent_lines(p1)
t2 = c1.tangent_lines(p2)
ta = t1 + t2
fig = plt.gcf()
ax = fig.gca()
ax.set_xlim((-10, 400))
ax.set_ylim((-10, 400))
ax.set_aspect(1)
img=np.zeros((400,400,3),dtype=np.uint8)
point_color=(255,0,0)
cv2.circle(img, (c1.center.x, c1.center.y), int(c1.radius), point_color, 0)
cv2.circle(img, (c2.center.x, c2.center