File size: 2,867 Bytes
3d1f2c9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
def _point_to_meters_inverse(p, w=105, h=68):
return np.array([p[0] * h, p[1] * w])
def _point_to_meters(p, w=105, h=68):
return np.array([p[0] * w, p[1] * h])
def _draw_field(width=105, height=68, fig_size=8, lines_color="#bcbcbc", background_color="white"):
ratio = width / float(height)
f, ax = plt.subplots(1, 1, figsize=(fig_size * ratio, fig_size), dpi=100)
if background_color:
ax.add_patch(patches.Rectangle((0, 0), width, height, color=background_color))
line_pts = [
[_point_to_meters([0, 0]), _point_to_meters([0, 1])],
[_point_to_meters([1, 0]), _point_to_meters([1, 1])],
[_point_to_meters([0, 1]), _point_to_meters([1, 1])],
[_point_to_meters([0, 0]), _point_to_meters([1, 0])],
]
for line_pt in line_pts:
ax.plot([line_pt[0][0], line_pt[1][0]], [line_pt[0][1], line_pt[1][1]], '-', alpha=0.8,
lw=1.5, zorder=2, color=lines_color)
line_pts = [
[_point_to_meters([0.5, 0]), _point_to_meters([0.5, 1])],
[[0, 24.85], [0, 2.85]],
[[0, 13.85], [16.5, 13.85]],
[[0, 54.15], [16.5, 54.15]],
[[16.5, 13.85], [16.5, 54.15]],
[[0, 24.85], [5.5, 24.85]],
[[0, 43.15], [5.5, 43.15]],
[[5.5, 24.85], [5.5, 43.15]],
[[105, 24.85], [105, 2.85]],
[[105, 13.85], [88.5, 13.85]],
[[105, 54.15], [88.5, 54.15]],
[[88.5, 13.85], [88.5, 54.15]],
[[105, 24.85], [99.5, 24.85]],
[[105, 43.15], [99.5, 43.15]],
[[99.5, 24.85], [99.5, 43.14]]
]
for line_pt in line_pts:
ax.plot([line_pt[0][0], line_pt[1][0]], [line_pt[0][1], line_pt[1][1]], '-',
alpha=0.8, lw=1.5, zorder=2, color=lines_color)
# Circles
ax.add_patch(patches.Wedge((94.0, 34.0), 9, 128, 232, fill=False, edgecolor=lines_color,
facecolor=lines_color, zorder=4, width=0.02))
ax.add_patch(patches.Wedge((11.0, 34.0), 9, 308, 52, fill=False, edgecolor=lines_color,
facecolor=lines_color, zorder=4, width=0.02))
ax.add_patch(patches.Wedge((52.5, 34), 9.5, 0, 360, fill=False, edgecolor=lines_color,
facecolor=lines_color, zorder=4, width=0.02))
# Ajouter des points verts pour les distinguer des lignes
keypoints = set()
for line_pt in line_pts:
keypoints.add(tuple(line_pt[0]))
keypoints.add(tuple(line_pt[1]))
for point in keypoints:
ax.plot(point[0], point[1], 'o', color='green', markersize=5, zorder=3)
plt.axis('off')
return f, ax
if __name__ == "__main__":
fig, ax = _draw_field()
plt.show() |