|
|

楼主 |
发表于 2026-7-23 17:47
|
显示全部楼层
import matplotlib.pyplot as plt
import numpy as np
# --- 1. 参数定义与坐标计算 ---
# 根据题目描述设定各点坐标
O = (0, 0)
A = (-1, 0)
F = (7, 0)
E = (6, 0)
# G点坐标: A点向左延伸 13*sqrt(2)
G_x = -1 - 13 * np.sqrt(2)
G = (G_x, 0)
# --- 2. 几何构造计算 ---
# 计算 FG 的中点(辅助圆圆心)和半径
center_FG = ((G[0] + F[0]) / 2, 0)
radius_FG = (F[0] - G[0]) / 2
# 计算垂线交点 M 的纵坐标
# 根据圆方程 (x - h)^2 + y^2 = r^2
# 当 x = E[0] 时,y^2 = r^2 - (E[0] - h)^2
# 也就是利用射影定理: EM^2 = GE * EF
GE_dist = E[0] - G[0]
EF_dist = F[0] - E[0]
EM_length_sq = GE_dist * EF_dist
EM_length = np.sqrt(EM_length_sq)
M = (E[0], EM_length)
N = (E[0], -EM_length)
# 计算最终棱长 MN / 8
MN_length = 2 * EM_length
calculated_cube_root_2 = MN_length / 8
# --- 3. 绘图 ---
fig, ax = plt.subplots(figsize=(12, 8))
# 绘制单位圆 O
unit_circle = plt.Circle((0, 0), 1, color='blue', fill=False, linestyle='--', label='Unit Circle O')
ax.add_artist(unit_circle)
# 绘制以 FG 为直径的辅助圆
aux_circle = plt.Circle(center_FG, radius_FG, color='purple', fill=False, linewidth=1.5, label='Circle with diameter FG')
ax.add_artist(aux_circle)
# 绘制关键点
points = {'O': O, 'A': A, 'F': F, 'E': E, 'G': G, 'M': M, 'N': N}
for name, pt in points.items():
ax.plot(pt[0], pt[1], 'ro')
# 调整标签位置避免重叠
offset_y = 0.3 if name != 'N' else -0.8
offset_x = 0.2 if name not in ['G', 'M', 'N'] else 0
ax.text(pt[0] + offset_x, pt[1] + offset_y, f'{name}{pt}', fontsize=10, ha='left')
# 绘制线段
ax.plot([G[0], F[0]], [0, 0], 'k-', alpha=0.3) # X轴部分
ax.plot([M[0], N[0]], [M[1], N[1]], 'g-', linewidth=2, label=f'MN Segment') # 垂线 MN
# 绘制示意图中的立方体(右上角示意)
# 这是一个简单的视觉示意,非严格投影
cube_size = calculated_cube_root_2 * 10 # 放大以便观察
ax.add_patch(plt.Rectangle((4, 2), cube_size, cube_size, fill=False, edgecolor='green'))
ax.add_patch(plt.Rectangle((4.5, 2.5), cube_size, cube_size, fill=False, edgecolor='green'))
ax.plot([4, 4.5], [2, 2.5], 'g-')
ax.plot([4+cube_size, 4.5+cube_size], [2, 2.5], 'g-')
ax.plot([4, 4.5], [2+cube_size, 2.5+cube_size], 'g-')
ax.plot([4+cube_size, 4.5+cube_size], [2+cube_size, 2.5+cube_size], 'g-')
# --- 4. 设置画布属性 ---
ax.set_xlim(G[0] - 1, F[0] + 2)
ax.set_ylim(-10, 10)
ax.axhline(0, color='black', linewidth=0.5)
ax.axvline(0, color='black', linewidth=0.5)
ax.set_aspect('equal', adjustable='box')
ax.grid(True, linestyle=':', alpha=0.6)
ax.legend(loc='upper right')
ax.set_title(f"Geometric Construction of Cube Root of 2\nCalculated Value: {calculated_cube_root_2:.6f}")
plt.show()
# --- 5. 输出验证结果 ---
print("-" * 30)
print("验证计算结果:")
print(f"G点坐标: ({G[0]:.4f}, 0)")
print(f"线段 GE 长度: {GE_dist:.4f}")
print(f"线段 EF 长度: {EF_dist:.4f}")
print(f"线段 MN 长度: {MN_length:.6f}")
print(f"最终棱长 (MN/8): {calculated_cube_root_2:.10f}")
print(f"理论值 ∛2: {np.cbrt(2):.10f}")
print(f"误差: {abs(calculated_cube_root_2 - np.cbrt(2)):.2e}")
|
|