Files
cumcm2024-code/A/2/visualize.py
2024-09-06 09:12:23 +08:00

48 lines
1.4 KiB
Python

import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import mpmath as mp
import json
import sys
def visualize_spiral(node_list):
plt.figure(figsize=(12, 12))
# 绘制灰色螺旋线
theta = np.linspace(0, node_list[0]["theta"], 1000)
x = [Theta2Dot(t)[0] for t in theta]
y = [Theta2Dot(t)[1] for t in theta]
plt.plot(x, y, color='gray', linewidth=0.5)
# 绘制节点和连接线
for i in range(len(node_list) - 1):
x1, y1 = node_list[i]["node"]
x2, y2 = node_list[i+1]["node"]
# 绘制红色节点
plt.plot(x1, y1, 'ro', markersize=3)
# 绘制蓝色连接线
plt.plot([x1, x2], [y1, y2], 'b-', linewidth=0.5)
# 计算并绘制长方形
dx = x2 - x1
dy = y2 - y1
length = np.sqrt(dx**2 + dy**2)
angle = np.arctan2(dy, dx)
rect_length = length + 0.55 # 0.275 * 2
rect_width = 0.3
rect_x = x1 - 0.275 * np.cos(angle)
rect_y = y1 - 0.275 * np.sin(angle)
rect = Rectangle((rect_x, rect_y), rect_length, rect_width,
angle=angle*180/np.pi, fill=False, edgecolor='g')
plt.gca().add_patch(rect)
plt.axis('equal')
plt.title(f"Spiral visualization at time={time_point}")
plt.show()
content=json.load(sys.stdin)
visualize_spiral(content)