Coverage for skcvideo/field_model.py: 0%

30 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-10-02 14:10 +0200

1import numpy as np 

2 

3CIRCLE_RADIUS = 9.15 

4GOAL_SIZE = 7.32 

5GOAL_AREA_SIZE = 5.5 

6PENALTY_AREA_SIZE = 16.5 

7PENALTY_MARK_DISTANCE = 11.0 

8 

9 

10# This file contains all the information concerning the soccer field model. 

11 

12 

13def create_field_objects(pitch_length=105.0, pitch_width=68.0): 

14 arc_angle = np.arccos((PENALTY_AREA_SIZE - PENALTY_MARK_DISTANCE) / CIRCLE_RADIUS) 

15 field_objects = { 

16 "Center Circle": { 

17 "type": "circle", 

18 "x": 0.0, 

19 "y": 0.0, 

20 "radius": CIRCLE_RADIUS, 

21 "startAngle": 0.0, 

22 "endAngle": 2.0 * np.pi, 

23 }, 

24 "Halfway line": { 

25 "type": "line", 

26 "start_point": (0.0, -pitch_width / 2.0), 

27 "end_point": (0.0, pitch_width / 2.0), 

28 }, 

29 } 

30 

31 for level, level_sign in zip(["Lower", "Upper"], [-1.0, 1.0]): 

32 x = pitch_length / 2.0 

33 y = pitch_width / 2.0 

34 field_objects[f"{level} touch line"] = { 

35 "type": "line", 

36 "start_point": ( 

37 -x, 

38 level_sign * y, 

39 ), 

40 "end_point": ( 

41 x, 

42 level_sign * y, 

43 ), 

44 } 

45 

46 for side, sign in zip(["Right", "Left"], [1.0, -1.0]): 

47 x = pitch_length / 2.0 

48 y = pitch_width / 2.0 

49 field_objects[f"{side} goal line"] = { 

50 "type": "line", 

51 "start_point": ( 

52 sign * x, 

53 -y, 

54 ), 

55 "end_point": ( 

56 sign * x, 

57 y, 

58 ), 

59 } 

60 

61 x = pitch_length / 2.0 - PENALTY_AREA_SIZE 

62 y = GOAL_SIZE / 2.0 + PENALTY_AREA_SIZE 

63 field_objects[f"{side} penalty line"] = { 

64 "type": "line", 

65 "start_point": ( 

66 sign * x, 

67 -y, 

68 ), 

69 "end_point": ( 

70 sign * x, 

71 y, 

72 ), 

73 } 

74 

75 x = pitch_length / 2.0 - GOAL_AREA_SIZE 

76 y = GOAL_SIZE / 2.0 + GOAL_AREA_SIZE 

77 field_objects[f"{side} goal area line"] = { 

78 "type": "line", 

79 "start_point": ( 

80 sign * x, 

81 -y, 

82 ), 

83 "end_point": ( 

84 sign * x, 

85 y, 

86 ), 

87 } 

88 

89 field_objects[f"{side} penalty arc"] = { 

90 "type": "circle", 

91 "x": sign * (pitch_length / 2.0 - PENALTY_MARK_DISTANCE), 

92 "y": 0.0, 

93 "radius": CIRCLE_RADIUS, 

94 "startAngle": -arc_angle - (sign + 1.0) * np.pi / 2.0, 

95 "endAngle": arc_angle - (sign + 1.0) * np.pi / 2.0, 

96 } 

97 

98 for level, level_sign in zip(["lower", "upper"], [-1.0, 1.0]): 

99 y = GOAL_SIZE / 2.0 + PENALTY_AREA_SIZE 

100 field_objects[f"{side} {level} penalty line"] = { 

101 "type": "line", 

102 "start_point": ( 

103 sign * pitch_length / 2.0, 

104 level_sign * y, 

105 ), 

106 "end_point": ( 

107 sign * (pitch_length / 2.0 - PENALTY_AREA_SIZE), 

108 level_sign * y, 

109 ), 

110 } 

111 

112 y = GOAL_SIZE / 2.0 + GOAL_AREA_SIZE 

113 field_objects[f"{side} {level} goal area line"] = { 

114 "type": "line", 

115 "start_point": ( 

116 sign * pitch_length / 2.0, 

117 level_sign * y, 

118 ), 

119 "end_point": ( 

120 sign * (pitch_length / 2.0 - GOAL_AREA_SIZE), 

121 level_sign * y, 

122 ), 

123 } 

124 return field_objects