File size: 31,998 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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
import numpy as np
class SoccerPitch:
"""Static class variables that are specified by the rules of the game """
GOAL_LINE_TO_PENALTY_MARK = 11.0
PENALTY_AREA_WIDTH = 40.32
PENALTY_AREA_LENGTH = 16.5
GOAL_AREA_WIDTH = 18.32
GOAL_AREA_LENGTH = 5.5
CENTER_CIRCLE_RADIUS = 9.15
GOAL_HEIGHT = 2.44
GOAL_LENGTH = 7.32
lines_classes = [
'Big rect. left bottom',
'Big rect. left main',
'Big rect. left top',
'Big rect. right bottom',
'Big rect. right main',
'Big rect. right top',
'Circle central',
'Circle left',
'Circle right',
'Goal left crossbar',
'Goal left post left ',
'Goal left post right',
'Goal right crossbar',
'Goal right post left',
'Goal right post right',
'Goal unknown',
'Line unknown',
'Middle line',
'Side line bottom',
'Side line left',
'Side line right',
'Side line top',
'Small rect. left bottom',
'Small rect. left main',
'Small rect. left top',
'Small rect. right bottom',
'Small rect. right main',
'Small rect. right top'
]
symetric_classes = {
'Side line top': 'Side line bottom',
'Side line bottom': 'Side line top',
'Side line left': 'Side line right',
'Middle line': 'Middle line',
'Side line right': 'Side line left',
'Big rect. left top': 'Big rect. right bottom',
'Big rect. left bottom': 'Big rect. right top',
'Big rect. left main': 'Big rect. right main',
'Big rect. right top': 'Big rect. left bottom',
'Big rect. right bottom': 'Big rect. left top',
'Big rect. right main': 'Big rect. left main',
'Small rect. left top': 'Small rect. right bottom',
'Small rect. left bottom': 'Small rect. right top',
'Small rect. left main': 'Small rect. right main',
'Small rect. right top': 'Small rect. left bottom',
'Small rect. right bottom': 'Small rect. left top',
'Small rect. right main': 'Small rect. left main',
'Circle left': 'Circle right',
'Circle central': 'Circle central',
'Circle right': 'Circle left',
'Goal left crossbar': 'Goal right crossbar',
'Goal left post left ': 'Goal right post left',
'Goal left post right': 'Goal right post right',
'Goal right crossbar': 'Goal left crossbar',
'Goal right post left': 'Goal left post left ',
'Goal right post right': 'Goal left post right',
'Goal unknown': 'Goal unknown',
'Line unknown': 'Line unknown'
}
# RGB values
palette = {
'Big rect. left bottom': (127, 0, 0),
'Big rect. left main': (102, 102, 102),
'Big rect. left top': (0, 0, 127),
'Big rect. right bottom': (86, 32, 39),
'Big rect. right main': (48, 77, 0),
'Big rect. right top': (14, 97, 100),
'Circle central': (0, 0, 255),
'Circle left': (255, 127, 0),
'Circle right': (0, 255, 255),
'Goal left crossbar': (255, 255, 200),
'Goal left post left ': (165, 255, 0),
'Goal left post right': (155, 119, 45),
'Goal right crossbar': (86, 32, 139),
'Goal right post left': (196, 120, 153),
'Goal right post right': (166, 36, 52),
'Goal unknown': (0, 0, 0),
'Line unknown': (0, 0, 0),
'Middle line': (255, 255, 0),
'Side line bottom': (255, 0, 255),
'Side line left': (0, 255, 150),
'Side line right': (0, 230, 0),
'Side line top': (230, 0, 0),
'Small rect. left bottom': (0, 150, 255),
'Small rect. left main': (254, 173, 225),
'Small rect. left top': (87, 72, 39),
'Small rect. right bottom': (122, 0, 255),
'Small rect. right main': (255, 255, 255),
'Small rect. right top': (153, 23, 153)
}
def __init__(self, pitch_length=105., pitch_width=68.):
"""
Initialize 3D coordinates of all elements of the soccer pitch.
:param pitch_length: According to FIFA rules, length belong to [90,120] meters
:param pitch_width: According to FIFA rules, length belong to [45,90] meters
"""
self.PITCH_LENGTH = pitch_length
self.PITCH_WIDTH = pitch_width
self.center_mark = np.array([0, 0, 0], dtype='float')
self.halfway_and_bottom_touch_line_mark = np.array([0, pitch_width / 2.0, 0], dtype='float')
self.halfway_and_top_touch_line_mark = np.array([0, -pitch_width / 2.0, 0], dtype='float')
self.halfway_line_and_center_circle_top_mark = np.array([0, -SoccerPitch.CENTER_CIRCLE_RADIUS, 0],
dtype='float')
self.halfway_line_and_center_circle_bottom_mark = np.array([0, SoccerPitch.CENTER_CIRCLE_RADIUS, 0],
dtype='float')
self.bottom_right_corner = np.array([pitch_length / 2.0, pitch_width / 2.0, 0], dtype='float')
self.bottom_left_corner = np.array([-pitch_length / 2.0, pitch_width / 2.0, 0], dtype='float')
self.top_right_corner = np.array([pitch_length / 2.0, -pitch_width / 2.0, 0], dtype='float')
self.top_left_corner = np.array([-pitch_length / 2.0, -pitch_width / 2.0, 0], dtype='float')
self.left_goal_bottom_left_post = np.array([-pitch_length / 2.0, SoccerPitch.GOAL_LENGTH / 2., 0.],
dtype='float')
self.left_goal_top_left_post = np.array(
[-pitch_length / 2.0, SoccerPitch.GOAL_LENGTH / 2., -SoccerPitch.GOAL_HEIGHT], dtype='float')
self.left_goal_bottom_right_post = np.array([-pitch_length / 2.0, -SoccerPitch.GOAL_LENGTH / 2., 0.],
dtype='float')
self.left_goal_top_right_post = np.array(
[-pitch_length / 2.0, -SoccerPitch.GOAL_LENGTH / 2., -SoccerPitch.GOAL_HEIGHT], dtype='float')
self.right_goal_bottom_left_post = np.array([pitch_length / 2.0, -SoccerPitch.GOAL_LENGTH / 2., 0.],
dtype='float')
self.right_goal_top_left_post = np.array(
[pitch_length / 2.0, -SoccerPitch.GOAL_LENGTH / 2., -SoccerPitch.GOAL_HEIGHT], dtype='float')
self.right_goal_bottom_right_post = np.array([pitch_length / 2.0, SoccerPitch.GOAL_LENGTH / 2., 0.],
dtype='float')
self.right_goal_top_right_post = np.array(
[pitch_length / 2.0, SoccerPitch.GOAL_LENGTH / 2., -SoccerPitch.GOAL_HEIGHT], dtype='float')
self.left_penalty_mark = np.array([-pitch_length / 2.0 + SoccerPitch.GOAL_LINE_TO_PENALTY_MARK, 0, 0],
dtype='float')
self.right_penalty_mark = np.array([pitch_length / 2.0 - SoccerPitch.GOAL_LINE_TO_PENALTY_MARK, 0, 0],
dtype='float')
self.left_penalty_area_top_right_corner = np.array(
[-pitch_length / 2.0 + SoccerPitch.PENALTY_AREA_LENGTH, -SoccerPitch.PENALTY_AREA_WIDTH / 2.0, 0],
dtype='float')
self.left_penalty_area_top_left_corner = np.array(
[-pitch_length / 2.0, -SoccerPitch.PENALTY_AREA_WIDTH / 2.0, 0],
dtype='float')
self.left_penalty_area_bottom_right_corner = np.array(
[-pitch_length / 2.0 + SoccerPitch.PENALTY_AREA_LENGTH, SoccerPitch.PENALTY_AREA_WIDTH / 2.0, 0],
dtype='float')
self.left_penalty_area_bottom_left_corner = np.array(
[-pitch_length / 2.0, SoccerPitch.PENALTY_AREA_WIDTH / 2.0, 0],
dtype='float')
self.right_penalty_area_top_right_corner = np.array(
[pitch_length / 2.0, -SoccerPitch.PENALTY_AREA_WIDTH / 2.0, 0],
dtype='float')
self.right_penalty_area_top_left_corner = np.array(
[pitch_length / 2.0 - SoccerPitch.PENALTY_AREA_LENGTH, -SoccerPitch.PENALTY_AREA_WIDTH / 2.0, 0],
dtype='float')
self.right_penalty_area_bottom_right_corner = np.array(
[pitch_length / 2.0, SoccerPitch.PENALTY_AREA_WIDTH / 2.0, 0],
dtype='float')
self.right_penalty_area_bottom_left_corner = np.array(
[pitch_length / 2.0 - SoccerPitch.PENALTY_AREA_LENGTH, SoccerPitch.PENALTY_AREA_WIDTH / 2.0, 0],
dtype='float')
self.left_goal_area_top_right_corner = np.array(
[-pitch_length / 2.0 + SoccerPitch.GOAL_AREA_LENGTH, -SoccerPitch.GOAL_AREA_WIDTH / 2.0, 0], dtype='float')
self.left_goal_area_top_left_corner = np.array([-pitch_length / 2.0, - SoccerPitch.GOAL_AREA_WIDTH / 2.0, 0],
dtype='float')
self.left_goal_area_bottom_right_corner = np.array(
[-pitch_length / 2.0 + SoccerPitch.GOAL_AREA_LENGTH, SoccerPitch.GOAL_AREA_WIDTH / 2.0, 0], dtype='float')
self.left_goal_area_bottom_left_corner = np.array([-pitch_length / 2.0, SoccerPitch.GOAL_AREA_WIDTH / 2.0, 0],
dtype='float')
self.right_goal_area_top_right_corner = np.array([pitch_length / 2.0, -SoccerPitch.GOAL_AREA_WIDTH / 2.0, 0],
dtype='float')
self.right_goal_area_top_left_corner = np.array(
[pitch_length / 2.0 - SoccerPitch.GOAL_AREA_LENGTH, -SoccerPitch.GOAL_AREA_WIDTH / 2.0, 0], dtype='float')
self.right_goal_area_bottom_right_corner = np.array([pitch_length / 2.0, SoccerPitch.GOAL_AREA_WIDTH / 2.0, 0],
dtype='float')
self.right_goal_area_bottom_left_corner = np.array(
[pitch_length / 2.0 - SoccerPitch.GOAL_AREA_LENGTH, SoccerPitch.GOAL_AREA_WIDTH / 2.0, 0], dtype='float')
x = -pitch_length / 2.0 + SoccerPitch.PENALTY_AREA_LENGTH;
dx = SoccerPitch.PENALTY_AREA_LENGTH - SoccerPitch.GOAL_LINE_TO_PENALTY_MARK;
y = -np.sqrt(SoccerPitch.CENTER_CIRCLE_RADIUS * SoccerPitch.CENTER_CIRCLE_RADIUS - dx * dx);
self.top_left_16M_penalty_arc_mark = np.array([x, y, 0], dtype='float')
x = pitch_length / 2.0 - SoccerPitch.PENALTY_AREA_LENGTH;
dx = SoccerPitch.PENALTY_AREA_LENGTH - SoccerPitch.GOAL_LINE_TO_PENALTY_MARK;
y = -np.sqrt(SoccerPitch.CENTER_CIRCLE_RADIUS * SoccerPitch.CENTER_CIRCLE_RADIUS - dx * dx);
self.top_right_16M_penalty_arc_mark = np.array([x, y, 0], dtype='float')
x = -pitch_length / 2.0 + SoccerPitch.PENALTY_AREA_LENGTH;
dx = SoccerPitch.PENALTY_AREA_LENGTH - SoccerPitch.GOAL_LINE_TO_PENALTY_MARK;
y = np.sqrt(SoccerPitch.CENTER_CIRCLE_RADIUS * SoccerPitch.CENTER_CIRCLE_RADIUS - dx * dx);
self.bottom_left_16M_penalty_arc_mark = np.array([x, y, 0], dtype='float')
x = pitch_length / 2.0 - SoccerPitch.PENALTY_AREA_LENGTH;
dx = SoccerPitch.PENALTY_AREA_LENGTH - SoccerPitch.GOAL_LINE_TO_PENALTY_MARK;
y = np.sqrt(SoccerPitch.CENTER_CIRCLE_RADIUS * SoccerPitch.CENTER_CIRCLE_RADIUS - dx * dx);
self.bottom_right_16M_penalty_arc_mark = np.array([x, y, 0], dtype='float')
# self.set_elevations(elevation)
self.point_dict = {}
self.point_dict["CENTER_MARK"] = self.center_mark
self.point_dict["L_PENALTY_MARK"] = self.left_penalty_mark
self.point_dict["R_PENALTY_MARK"] = self.right_penalty_mark
self.point_dict["TL_PITCH_CORNER"] = self.top_left_corner
self.point_dict["BL_PITCH_CORNER"] = self.bottom_left_corner
self.point_dict["TR_PITCH_CORNER"] = self.top_right_corner
self.point_dict["BR_PITCH_CORNER"] = self.bottom_right_corner
self.point_dict["L_PENALTY_AREA_TL_CORNER"] = self.left_penalty_area_top_left_corner
self.point_dict["L_PENALTY_AREA_TR_CORNER"] = self.left_penalty_area_top_right_corner
self.point_dict["L_PENALTY_AREA_BL_CORNER"] = self.left_penalty_area_bottom_left_corner
self.point_dict["L_PENALTY_AREA_BR_CORNER"] = self.left_penalty_area_bottom_right_corner
self.point_dict["R_PENALTY_AREA_TL_CORNER"] = self.right_penalty_area_top_left_corner
self.point_dict["R_PENALTY_AREA_TR_CORNER"] = self.right_penalty_area_top_right_corner
self.point_dict["R_PENALTY_AREA_BL_CORNER"] = self.right_penalty_area_bottom_left_corner
self.point_dict["R_PENALTY_AREA_BR_CORNER"] = self.right_penalty_area_bottom_right_corner
self.point_dict["L_GOAL_AREA_TL_CORNER"] = self.left_goal_area_top_left_corner
self.point_dict["L_GOAL_AREA_TR_CORNER"] = self.left_goal_area_top_right_corner
self.point_dict["L_GOAL_AREA_BL_CORNER"] = self.left_goal_area_bottom_left_corner
self.point_dict["L_GOAL_AREA_BR_CORNER"] = self.left_goal_area_bottom_right_corner
self.point_dict["R_GOAL_AREA_TL_CORNER"] = self.right_goal_area_top_left_corner
self.point_dict["R_GOAL_AREA_TR_CORNER"] = self.right_goal_area_top_right_corner
self.point_dict["R_GOAL_AREA_BL_CORNER"] = self.right_goal_area_bottom_left_corner
self.point_dict["R_GOAL_AREA_BR_CORNER"] = self.right_goal_area_bottom_right_corner
self.point_dict["L_GOAL_TL_POST"] = self.left_goal_top_left_post
self.point_dict["L_GOAL_TR_POST"] = self.left_goal_top_right_post
self.point_dict["L_GOAL_BL_POST"] = self.left_goal_bottom_left_post
self.point_dict["L_GOAL_BR_POST"] = self.left_goal_bottom_right_post
self.point_dict["R_GOAL_TL_POST"] = self.right_goal_top_left_post
self.point_dict["R_GOAL_TR_POST"] = self.right_goal_top_right_post
self.point_dict["R_GOAL_BL_POST"] = self.right_goal_bottom_left_post
self.point_dict["R_GOAL_BR_POST"] = self.right_goal_bottom_right_post
self.point_dict["T_TOUCH_AND_HALFWAY_LINES_INTERSECTION"] = self.halfway_and_top_touch_line_mark
self.point_dict["B_TOUCH_AND_HALFWAY_LINES_INTERSECTION"] = self.halfway_and_bottom_touch_line_mark
self.point_dict["T_HALFWAY_LINE_AND_CENTER_CIRCLE_INTERSECTION"] = self.halfway_line_and_center_circle_top_mark
self.point_dict[
"B_HALFWAY_LINE_AND_CENTER_CIRCLE_INTERSECTION"] = self.halfway_line_and_center_circle_bottom_mark
self.point_dict["TL_16M_LINE_AND_PENALTY_ARC_INTERSECTION"] = self.top_left_16M_penalty_arc_mark
self.point_dict["BL_16M_LINE_AND_PENALTY_ARC_INTERSECTION"] = self.bottom_left_16M_penalty_arc_mark
self.point_dict["TR_16M_LINE_AND_PENALTY_ARC_INTERSECTION"] = self.top_right_16M_penalty_arc_mark
self.point_dict["BR_16M_LINE_AND_PENALTY_ARC_INTERSECTION"] = self.bottom_right_16M_penalty_arc_mark
self.line_extremities = dict()
self.line_extremities["Big rect. left bottom"] = (self.point_dict["L_PENALTY_AREA_BL_CORNER"],
self.point_dict["L_PENALTY_AREA_BR_CORNER"])
self.line_extremities["Big rect. left top"] = (self.point_dict["L_PENALTY_AREA_TL_CORNER"],
self.point_dict["L_PENALTY_AREA_TR_CORNER"])
self.line_extremities["Big rect. left main"] = (self.point_dict["L_PENALTY_AREA_TR_CORNER"],
self.point_dict["L_PENALTY_AREA_BR_CORNER"])
self.line_extremities["Big rect. right bottom"] = (self.point_dict["R_PENALTY_AREA_BL_CORNER"],
self.point_dict["R_PENALTY_AREA_BR_CORNER"])
self.line_extremities["Big rect. right top"] = (self.point_dict["R_PENALTY_AREA_TL_CORNER"],
self.point_dict["R_PENALTY_AREA_TR_CORNER"])
self.line_extremities["Big rect. right main"] = (self.point_dict["R_PENALTY_AREA_TL_CORNER"],
self.point_dict["R_PENALTY_AREA_BL_CORNER"])
self.line_extremities["Small rect. left bottom"] = (self.point_dict["L_GOAL_AREA_BL_CORNER"],
self.point_dict["L_GOAL_AREA_BR_CORNER"])
self.line_extremities["Small rect. left top"] = (self.point_dict["L_GOAL_AREA_TL_CORNER"],
self.point_dict["L_GOAL_AREA_TR_CORNER"])
self.line_extremities["Small rect. left main"] = (self.point_dict["L_GOAL_AREA_TR_CORNER"],
self.point_dict["L_GOAL_AREA_BR_CORNER"])
self.line_extremities["Small rect. right bottom"] = (self.point_dict["R_GOAL_AREA_BL_CORNER"],
self.point_dict["R_GOAL_AREA_BR_CORNER"])
self.line_extremities["Small rect. right top"] = (self.point_dict["R_GOAL_AREA_TL_CORNER"],
self.point_dict["R_GOAL_AREA_TR_CORNER"])
self.line_extremities["Small rect. right main"] = (self.point_dict["R_GOAL_AREA_TL_CORNER"],
self.point_dict["R_GOAL_AREA_BL_CORNER"])
self.line_extremities["Side line top"] = (self.point_dict["TL_PITCH_CORNER"],
self.point_dict["TR_PITCH_CORNER"])
self.line_extremities["Side line bottom"] = (self.point_dict["BL_PITCH_CORNER"],
self.point_dict["BR_PITCH_CORNER"])
self.line_extremities["Side line left"] = (self.point_dict["TL_PITCH_CORNER"],
self.point_dict["BL_PITCH_CORNER"])
self.line_extremities["Side line right"] = (self.point_dict["TR_PITCH_CORNER"],
self.point_dict["BR_PITCH_CORNER"])
self.line_extremities["Middle line"] = (self.point_dict["T_TOUCH_AND_HALFWAY_LINES_INTERSECTION"],
self.point_dict["B_TOUCH_AND_HALFWAY_LINES_INTERSECTION"])
self.line_extremities["Goal left crossbar"] = (self.point_dict["L_GOAL_TR_POST"],
self.point_dict["L_GOAL_TL_POST"])
self.line_extremities["Goal left post left "] = (self.point_dict["L_GOAL_TL_POST"],
self.point_dict["L_GOAL_BL_POST"])
self.line_extremities["Goal left post right"] = (self.point_dict["L_GOAL_TR_POST"],
self.point_dict["L_GOAL_BR_POST"])
self.line_extremities["Goal right crossbar"] = (self.point_dict["R_GOAL_TL_POST"],
self.point_dict["R_GOAL_TR_POST"])
self.line_extremities["Goal right post left"] = (self.point_dict["R_GOAL_TL_POST"],
self.point_dict["R_GOAL_BL_POST"])
self.line_extremities["Goal right post right"] = (self.point_dict["R_GOAL_TR_POST"],
self.point_dict["R_GOAL_BR_POST"])
self.line_extremities["Circle right"] = (self.point_dict["TR_16M_LINE_AND_PENALTY_ARC_INTERSECTION"],
self.point_dict["BR_16M_LINE_AND_PENALTY_ARC_INTERSECTION"])
self.line_extremities["Circle left"] = (self.point_dict["TL_16M_LINE_AND_PENALTY_ARC_INTERSECTION"],
self.point_dict["BL_16M_LINE_AND_PENALTY_ARC_INTERSECTION"])
self.line_extremities_keys = dict()
self.line_extremities_keys["Big rect. left bottom"] = ("L_PENALTY_AREA_BL_CORNER",
"L_PENALTY_AREA_BR_CORNER")
self.line_extremities_keys["Big rect. left top"] = ("L_PENALTY_AREA_TL_CORNER",
"L_PENALTY_AREA_TR_CORNER")
self.line_extremities_keys["Big rect. left main"] = ("L_PENALTY_AREA_TR_CORNER",
"L_PENALTY_AREA_BR_CORNER")
self.line_extremities_keys["Big rect. right bottom"] = ("R_PENALTY_AREA_BL_CORNER",
"R_PENALTY_AREA_BR_CORNER")
self.line_extremities_keys["Big rect. right top"] = ("R_PENALTY_AREA_TL_CORNER",
"R_PENALTY_AREA_TR_CORNER")
self.line_extremities_keys["Big rect. right main"] = ("R_PENALTY_AREA_TL_CORNER",
"R_PENALTY_AREA_BL_CORNER")
self.line_extremities_keys["Small rect. left bottom"] = ("L_GOAL_AREA_BL_CORNER",
"L_GOAL_AREA_BR_CORNER")
self.line_extremities_keys["Small rect. left top"] = ("L_GOAL_AREA_TL_CORNER",
"L_GOAL_AREA_TR_CORNER")
self.line_extremities_keys["Small rect. left main"] = ("L_GOAL_AREA_TR_CORNER",
"L_GOAL_AREA_BR_CORNER")
self.line_extremities_keys["Small rect. right bottom"] = ("R_GOAL_AREA_BL_CORNER",
"R_GOAL_AREA_BR_CORNER")
self.line_extremities_keys["Small rect. right top"] = ("R_GOAL_AREA_TL_CORNER",
"R_GOAL_AREA_TR_CORNER")
self.line_extremities_keys["Small rect. right main"] = ("R_GOAL_AREA_TL_CORNER",
"R_GOAL_AREA_BL_CORNER")
self.line_extremities_keys["Side line top"] = ("TL_PITCH_CORNER",
"TR_PITCH_CORNER")
self.line_extremities_keys["Side line bottom"] = ("BL_PITCH_CORNER",
"BR_PITCH_CORNER")
self.line_extremities_keys["Side line left"] = ("TL_PITCH_CORNER",
"BL_PITCH_CORNER")
self.line_extremities_keys["Side line right"] = ("TR_PITCH_CORNER",
"BR_PITCH_CORNER")
self.line_extremities_keys["Middle line"] = ("T_TOUCH_AND_HALFWAY_LINES_INTERSECTION",
"B_TOUCH_AND_HALFWAY_LINES_INTERSECTION")
self.line_extremities_keys["Goal left crossbar"] = ("L_GOAL_TR_POST",
"L_GOAL_TL_POST")
self.line_extremities_keys["Goal left post left "] = ("L_GOAL_TL_POST",
"L_GOAL_BL_POST")
self.line_extremities_keys["Goal left post right"] = ("L_GOAL_TR_POST",
"L_GOAL_BR_POST")
self.line_extremities_keys["Goal right crossbar"] = ("R_GOAL_TL_POST",
"R_GOAL_TR_POST")
self.line_extremities_keys["Goal right post left"] = ("R_GOAL_TL_POST",
"R_GOAL_BL_POST")
self.line_extremities_keys["Goal right post right"] = ("R_GOAL_TR_POST",
"R_GOAL_BR_POST")
self.line_extremities_keys["Circle right"] = ("TR_16M_LINE_AND_PENALTY_ARC_INTERSECTION",
"BR_16M_LINE_AND_PENALTY_ARC_INTERSECTION")
self.line_extremities_keys["Circle left"] = ("TL_16M_LINE_AND_PENALTY_ARC_INTERSECTION",
"BL_16M_LINE_AND_PENALTY_ARC_INTERSECTION")
def points(self):
return [
self.center_mark,
self.halfway_and_bottom_touch_line_mark,
self.halfway_and_top_touch_line_mark,
self.halfway_line_and_center_circle_top_mark,
self.halfway_line_and_center_circle_bottom_mark,
self.bottom_right_corner,
self.bottom_left_corner,
self.top_right_corner,
self.top_left_corner,
self.left_penalty_mark,
self.right_penalty_mark,
self.left_penalty_area_top_right_corner,
self.left_penalty_area_top_left_corner,
self.left_penalty_area_bottom_right_corner,
self.left_penalty_area_bottom_left_corner,
self.right_penalty_area_top_right_corner,
self.right_penalty_area_top_left_corner,
self.right_penalty_area_bottom_right_corner,
self.right_penalty_area_bottom_left_corner,
self.left_goal_area_top_right_corner,
self.left_goal_area_top_left_corner,
self.left_goal_area_bottom_right_corner,
self.left_goal_area_bottom_left_corner,
self.right_goal_area_top_right_corner,
self.right_goal_area_top_left_corner,
self.right_goal_area_bottom_right_corner,
self.right_goal_area_bottom_left_corner,
self.top_left_16M_penalty_arc_mark,
self.top_right_16M_penalty_arc_mark,
self.bottom_left_16M_penalty_arc_mark,
self.bottom_right_16M_penalty_arc_mark,
self.left_goal_top_left_post,
self.left_goal_top_right_post,
self.left_goal_bottom_left_post,
self.left_goal_bottom_right_post,
self.right_goal_top_left_post,
self.right_goal_top_right_post,
self.right_goal_bottom_left_post,
self.right_goal_bottom_right_post
]
def sample_field_points(self, dist=0.1, dist_circles=0.2):
"""
Samples each pitch element every dist meters, returns a dictionary associating the class of the element with a list of points sampled along this element.
:param dist: the distance in meters between each point sampled
:param dist_circles: the distance in meters between each point sampled on circles
:return: a dictionary associating the class of the element with a list of points sampled along this element.
"""
polylines = dict()
center = self.point_dict["CENTER_MARK"]
fromAngle = 0.
toAngle = 2 * np.pi
if toAngle < fromAngle:
toAngle += 2 * np.pi
x1 = center[0] + np.cos(fromAngle) * SoccerPitch.CENTER_CIRCLE_RADIUS
y1 = center[1] + np.sin(fromAngle) * SoccerPitch.CENTER_CIRCLE_RADIUS
z1 = 0.
point = np.array((x1, y1, z1))
polyline = [point]
length = SoccerPitch.CENTER_CIRCLE_RADIUS * (toAngle - fromAngle)
nb_pts = int(length / dist_circles)
dangle = dist_circles / SoccerPitch.CENTER_CIRCLE_RADIUS
for i in range(1, nb_pts):
angle = fromAngle + i * dangle
x = center[0] + np.cos(angle) * SoccerPitch.CENTER_CIRCLE_RADIUS
y = center[1] + np.sin(angle) * SoccerPitch.CENTER_CIRCLE_RADIUS
z = 0
point = np.array((x, y, z))
polyline.append(point)
polylines["Circle central"] = polyline
for key, line in self.line_extremities.items():
if "Circle" in key:
if key == "Circle right":
top = self.point_dict["TR_16M_LINE_AND_PENALTY_ARC_INTERSECTION"]
bottom = self.point_dict["BR_16M_LINE_AND_PENALTY_ARC_INTERSECTION"]
center = self.point_dict["R_PENALTY_MARK"]
toAngle = np.arctan2(top[1] - center[1],
top[0] - center[0]) + 2 * np.pi
fromAngle = np.arctan2(bottom[1] - center[1],
bottom[0] - center[0]) + 2 * np.pi
elif key == "Circle left":
top = self.point_dict["TL_16M_LINE_AND_PENALTY_ARC_INTERSECTION"]
bottom = self.point_dict["BL_16M_LINE_AND_PENALTY_ARC_INTERSECTION"]
center = self.point_dict["L_PENALTY_MARK"]
fromAngle = np.arctan2(top[1] - center[1],
top[0] - center[0]) + 2 * np.pi
toAngle = np.arctan2(bottom[1] - center[1],
bottom[0] - center[0]) + 2 * np.pi
if toAngle < fromAngle:
toAngle += 2 * np.pi
x1 = center[0] + np.cos(fromAngle) * SoccerPitch.CENTER_CIRCLE_RADIUS
y1 = center[1] + np.sin(fromAngle) * SoccerPitch.CENTER_CIRCLE_RADIUS
z1 = 0.
xn = center[0] + np.cos(toAngle) * SoccerPitch.CENTER_CIRCLE_RADIUS
yn = center[1] + np.sin(toAngle) * SoccerPitch.CENTER_CIRCLE_RADIUS
zn = 0.
start = np.array((x1, y1, z1))
end = np.array((xn, yn, zn))
polyline = [start]
length = SoccerPitch.CENTER_CIRCLE_RADIUS * (toAngle - fromAngle)
nb_pts = int(length / dist_circles)
dangle = dist_circles / SoccerPitch.CENTER_CIRCLE_RADIUS
for i in range(1, nb_pts + 1):
angle = fromAngle + i * dangle
x = center[0] + np.cos(angle) * SoccerPitch.CENTER_CIRCLE_RADIUS
y = center[1] + np.sin(angle) * SoccerPitch.CENTER_CIRCLE_RADIUS
z = 0
point = np.array((x, y, z))
polyline.append(point)
polyline.append(end)
polylines[key] = polyline
else:
start = line[0]
end = line[1]
polyline = [start]
total_dist = np.sqrt(np.sum(np.square(start - end)))
nb_pts = int(total_dist / dist - 1)
v = end - start
v /= np.linalg.norm(v)
prev_pt = start
for i in range(nb_pts):
pt = prev_pt + dist * v
prev_pt = pt
polyline.append(pt)
polyline.append(end)
polylines[key] = polyline
return polylines
def get_2d_homogeneous_line(self, line_name):
"""
For lines belonging to the pitch lawn plane returns its 2D homogenous equation coefficients
:param line_name
:return: an array containing the three coefficients of the line
"""
# ensure line in football pitch plane
if line_name in self.line_extremities.keys() and \
"post" not in line_name and \
"crossbar" not in line_name and "Circle" not in line_name:
extremities = self.line_extremities[line_name]
p1 = np.array([extremities[0][0], extremities[0][1], 1], dtype="float")
p2 = np.array([extremities[1][0], extremities[1][1], 1], dtype="float")
line = np.cross(p1, p2)
return line
return None
|