make_soccer_map.R 4.18 KB
Newer Older
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
make_soccer_map_pp <- function(rcg) {
    soocer_field = c(6000,104,68)
    names(soocer_field) = c("time","length","width")
    soccer_map <- array(0, dim = c(6000,13,104,68))

    for(i in seq_along(rcg)){
        # SP - (x,y) location	1 on attacking players’ location (x,y)
        px <- round(rcg$x[i])+soocer_field["length"]/2
        py <- round(rcg$y[i])+soocer_field["width"]/2
        bx <- round(rcg$ball_x[i])+soocer_field["length"]/2
        by <- round(rcg$ball_y[i])+soocer_field["width"]/2
        step <- rcg$step[i]
        if(rcg$side[i]=="l"){
            soccer_map[step,1,px,py] = rcg$unum[i]
            soccer_map[step,3,px,py] = rcg$vx[i]
            soccer_map[step,4,px,py] = rcg$vy[i]
        }else if (rcg$side[i]=="r"){
            soccer_map[step,2,px,py] = rcg$unum[i]
            soccer_map[step,5,px,py] = rcg$vx[i]
            soccer_map[step,6,px,py] = rcg$vy[i]
        }
        soccer_map[step,7,px,py] = atan(py/(soocer_field["length"]/2 - px))
        dist_p_b = sqrt((bx-px)^2+(by-py)^2)
        dist_p_g = sqrt(((soocer_field["length"]/2)-px)^2+(py)^2)

        soccer_map[step,8,px,py] = (py-by) / dist_p_b
        soccer_map[step,9,px,py] = (px-bx) / dist_p_b
        soccer_map[step,10,px,py] = py / dist_p_g
        soccer_map[step,11,px,py] = px / dist_p_g
        soccer_map[step,12,px,py] = dist_p_b
        soccer_map[step,13,px,py] = dist_p_g
    }
    return(soccer_map)
}

make_soccer_map_ps <- function(rcg) {
    soocer_field = c(6000,104,68)
    names(soocer_field) = c("time","length","width")
    soccer_map <- array(0, dim = c(6000,13,104,68))

    for(i in seq_along(rcg)){
        # SP - (x,y) location	1 on attacking players’ location (x,y)
        px <- round(rcg$x[i])+soocer_field["length"]/2
        py <- round(rcg$y[i])+soocer_field["width"]/2
        bx <- round(rcg$ball_x[i])+soocer_field["length"]/2
        by <- round(rcg$ball_y[i])+soocer_field["width"]/2
        step <- rcg$step[i]
        if(rcg$side[i]=="l"){
            soccer_map[step,1,px,py] = rcg$unum[i]
            soccer_map[step,3,px,py] = rcg$vx[i]
            soccer_map[step,4,px,py] = rcg$vy[i]
        }else if (rcg$side[i]=="r"){
            soccer_map[step,2,px,py] = rcg$unum[i]
            soccer_map[step,5,px,py] = rcg$vx[i]
            soccer_map[step,6,px,py] = rcg$vy[i]
        }
        soccer_map[step,7,px,py] = atan(py/(soocer_field["length"]/2 - px))
        dist_p_b = sqrt((bx-px)^2+(by-py)^2)
        dist_p_g = sqrt(((soocer_field["length"]/2)-px)^2+(py)^2)

        soccer_map[step,8,px,py] = (py-by) / dist_p_b
        soccer_map[step,9,px,py] = (px-bx) / dist_p_b
        soccer_map[step,10,px,py] = py / dist_p_g
        soccer_map[step,11,px,py] = px / dist_p_g
        soccer_map[step,12,px,py] = dist_p_b
        soccer_map[step,13,px,py] = dist_p_g
    }
    return(soccer_map)
}

make_soccer_map_pe <- function(rcg) {
    soocer_field = c(6000,104,68)
    names(soocer_field) = c("time","length","width")
    soccer_map <- array(0, dim = c(6000,13,104,68))

    for(i in seq_along(rcg)){
        # SP - (x,y) location	1 on attacking players’ location (x,y)
        px <- round(rcg$x[i])+soocer_field["length"]/2
        py <- round(rcg$y[i])+soocer_field["width"]/2
        bx <- round(rcg$ball_x[i])+soocer_field["length"]/2
        by <- round(rcg$ball_y[i])+soocer_field["width"]/2
        step <- rcg$step[i]
        if(rcg$side[i]=="l"){
            soccer_map[step,1,px,py] = rcg$unum[i]
            soccer_map[step,3,px,py] = rcg$vx[i]
            soccer_map[step,4,px,py] = rcg$vy[i]
        }else if (rcg$side[i]=="r"){
            soccer_map[step,2,px,py] = rcg$unum[i]
            soccer_map[step,5,px,py] = rcg$vx[i]
            soccer_map[step,6,px,py] = rcg$vy[i]
        }
        soccer_map[step,7,px,py] = atan(py/(soocer_field["length"]/2 - px))
        dist_p_b = sqrt((bx-px)^2+(by-py)^2)
        dist_p_g = sqrt(((soocer_field["length"]/2)-px)^2+(py)^2)

        soccer_map[step,8,px,py] = (py-by) / dist_p_b
        soccer_map[step,9,px,py] = (px-bx) / dist_p_b
        soccer_map[step,10,px,py] = py / dist_p_g
        soccer_map[step,11,px,py] = px / dist_p_g
        soccer_map[step,12,px,py] = dist_p_b
        soccer_map[step,13,px,py] = dist_p_g
    }
    return(soccer_map)
}