Skip to contents

Convert x, y coordinates to zones

Usage

dv_xy2zone(x, y = NULL, as_for_serve = FALSE)

Arguments

x

numeric: the x coordinate

y

numeric: the y coordinate. If y is NULL, x will be treated as a grid index (see dv_index2xy)

as_for_serve

logical: if TRUE, treat the zones as if they refer to serving locations (i.e. zone 7 in between zones 5 and 6, and zone 9 in between zones 6 and 1)

Value

A numeric vector giving the zone number

Examples

if (FALSE) {

## a bunch of random points on and around the court
idx <- round(runif(100, min = 1, max = 10000))

## convert to zones
zn <- dv_xy2zone(x = idx)

## or, equivalently, convert the index to xy values first
idx_xy <- dv_index2xy(idx)
zn <- dv_xy2zone(x = idx_xy$x, idx_xy$y)

## plot
ggplot(idx_xy, aes(x, y, fill = as.factor(zn))) + geom_point(shape = 21) +
  ggcourt(labels = NULL)

## the points shoud be coloured by zone
}