Python 已知平面坐标系中三角形的三条边和两点位置,求第三个点位置
也就是相交圆的交点,直接上代码
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
import math
x1, y1, a = 9, 8, 2
x2, y2, b = 10, 11, 3
## 计算两点的距离
c = math.sqrt(math.pow((x1-x2), 2) + math.pow((y1-y2), 2))
# 抛出不相交
if a + b <= c:
print('不相交')
# 抛出同心圆
elif x1==x2 and y1 == y2:
print('同心圆')
elif y1 < y2:
# 主要是计算夹角
x_3 = x1 + a*math.cos(math.acos((x2-x1)/c) - math.acos((a**2 + c**2 - b**2)/(2*c)/a))
y_3 = y1 + a*math.sin(math.acos((x2-x1)/c) - math.acos((a**2 + c**2 - b**2)/(2*c)/a))
x_4 = x1 + a*math.cos(math.acos((x2-x1)/c) + math.acos((a**2 + c**2 - b**2)/(2*c)/a))
y_4 = y1 + a*math.sin(math.acos((x2-x1)/c) + math.acos((a**2 + c**2 - b**2)/(2*c)/a))
else:
x_3 = x1 + a*math.cos(math.acos((x2-x1)/c) - math.acos((a**2 + c**2 - b**2)/(2*c)/a))
y_3 = y1 - a*math.sin(math.acos((x2-x1)/c) - math.acos((a**2 + c**2 - b**2)/(2*c)/a))
x_4 = x1 + a*math.cos(math.acos((x2-x1)/c) + math.acos((a**2 + c**2 - b**2)/(2*c)/a))
y_4 = y1 - a*math.sin(math.acos((x2-x1)/c) + math.acos((a**2 + c**2 - b**2)/(2*c)/a))
fig, ax = plt.subplots(1, 1)
plt.axis('equal')
ax.scatter(x1, y1, label=f'{a}_a')
ax.scatter(x2, y2, label=f'{b}_b')
ax.add_patch(Circle((x1, y1), a, color="blue", fill=False, alpha=1))
ax.add_patch(Circle((x2, y2), b, color="blue", fill=False, alpha=1))
ax.plot([x1,x2], [y1, y2])
ax.scatter(x_3, y_3, label='——1')
ax.scatter(x_4, y_4, label='——2')
plt.legend()
plt.grid()
本文来自博客园,作者:赫凯,转载请注明原文链接:https://www.cnblogs.com/heKaiii/p/17137346.html