circles_polygon: Generate coordinates of circles cropped by a polygon

View source: R/utility_geometry.R

circles_polygonR Documentation

Generate coordinates of circles cropped by a polygon

Description

Generates the coordinates of a number of circles based on positions of the midpoint and their radii. The circles can be cropped by a polygon if polygon points are provided.

Usage

circles_polygon(xm = 0.1, ym = 0.1, r = 1, xp = NULL, yp = NULL, nc = 91)

Arguments

xm, ym

x and y coordinates of midpoints of circles (arrays)

r

radii of circles (array with same length as 'xm' and 'ym')

xp, yp

x and y coordinates of polygon, defined in clockwise order

nc

number of points to use to draw a full circle

Value

a tibble with fields 'x' and 'y' for the coordinates, and a field 'id' to indicate which circle the point belongs to

Examples

#polygon coordinates
xp <- c(0, 1, 2, 1)
yp <- c(0, 1, 1, 0)

#circle coordinates and radii
xm <- c(0.5, 0.8)
ym <- c(0.5, 0.1)
r <- c(0.4, 0.6)

#get coordinates, and crop with polygon
dc <- circles_polygon(xm, ym, r, xp = xp, yp = yp)

#plot
ggplot2::ggplot() +
  ggplot2::geom_polygon(
  ggplot2::aes(x = xp, y = yp),
  fill = "grey80"
) +
ggplot2::geom_polygon(
  data = dc,
  ggplot2::aes(x = x, y = y, fill = as.factor(id), color = as.factor(id)),
  alpha = 0.2
) +
ggplot2::coord_fixed(ratio = 1) +
ggplot2::theme(legend.position = "none")

GJMeijer/soilmech documentation built on May 22, 2022, 10:39 a.m.