如何用代码绘制一个操场
时间: 2024-09-27 18:10:41 浏览: 64
在Python中,我们可以使用matplotlib库来绘制一个简单的操场模型。这里是一个基本的例子,我们假设操场是一个长方形,中心有一个半径为R的圆形篮球场:
```python
import matplotlib.pyplot as plt
import numpy as np
# 操场和篮球场尺寸
playground_length = 80 # 操场长度 (米)
playground_width = 50 # 操场宽度 (米)
basketball_court_radius = 10 # 篮球场半径 (米)
def draw_playground():
fig, ax = plt.subplots()
# 绘制操场边界
ax.plot([-playground_length / 2, playground_length / 2], [0, 0], color='gray', linestyle='dashed')
ax.plot([0, 0], [-playground_width / 2, playground_width / 2], color='gray', linestyle='dashed')
# 绘制篮球场圆心
court_center = (-playground_length / 4, playground_width / 4)
ax.scatter(court_center[0], court_center[1], color='red', marker='o', s=200)
# 绘制篮球场圆
circle = plt.Circle(court_center, basketball_court_radius, fill=False, edgecolor='black')
ax.add_patch(circle)
# 设置坐标轴范围和标题
ax.set_xlim(-playground_length / 2, playground_length / 2)
ax.set_ylim(-playground_width / 2, playground_width / 2)
ax.set_aspect('equal') # 保持纵横比例一致
ax.set_title('简单操场示意图')
draw_playground()
plt.show()
阅读全文