fGetBlocksThroughWhichLineSegmentsPass: Identifies the blocks in a grid through which a line segment...

View source: R/fGetBlocksThroughWhichLineSegmentsPass.R

fGetBlocksThroughWhichLineSegmentsPassR Documentation

Identifies the blocks in a grid through which a line segment goes

Description

Identifies the blocks in a grid through which a line segment goes

Usage

fGetBlocksThroughWhichLineSegmentsPass(
  dt_ls,
  x_lim = c(-60, 60),
  y_lim = c(-40, 40),
  x_gap = 5,
  y_gap = 5
)

Arguments

dt_ls

a data.table with x, y, xend, yend, and optionally id

x_lim

the span of x coordinates on your grid - c(min x, max x)

y_lim

the span of x coordinates on your grid - c(min y, max y)

x_gap

the spacing between blocks of the grid on the x dim

y_gap

the spacing between blocks of the grid on the y dim

Examples


library(data.table)
dt_ls = rbind(
  data.table(x = -27, y = 7, xend = -37, yend = 22, id = 1),
  data.table(x = 27, y = 7, xend = 37, yend = 22, id = 2),
  data.table(x = 27, y = -7, xend = 37, yend = -17, id = 3),
  data.table(x = -27, y = -7, xend = -37, yend = -17, id = 4),
  data.table(x = -25, y = 25, xend = -10, yend = 35, id = 5),
  data.table(x = 25, y = 25, xend = 10, yend = 35, id = 6),
  data.table(x = 25, y = -25, xend = 10, yend = -35, id = 7),
  data.table(x = -25, y = -25, xend = -10, yend = -35, id = 8),
  data.table(x = -8, y = -20, xend = 8, yend = -20, id = 9),
  data.table(x = 0, y = 0, xend = 0, yend = 20, id = 10)
)
dt_grids_ls = fGetBlocksThroughWhichLineSegmentsPass(
  dt_ls = dt_ls,
  x_lim = c(-60,60),
  y_lim = c(-40,40),
  x_gap = 5,
  y_gap = 5
)


library(ggplot2)
ggplot() +
  geom_tile(
     data = dt_grids_ls,
     aes(x = x_block, y = y_block),
     fill = 'cyan',
     color = 'black'
  ) +
  geom_segment(
     data = dt_ls,
     aes(x = x, y = y, xend = xend, yend = yend),
     color = 'red',
     arrow=arrow(type="closed",ends="last",length=unit(0.1,"cm"))
  ) +
  coord_fixed()


thecomeonman/POV documentation built on Sept. 24, 2022, 8:31 p.m.