plotDelaunay2D: Plot 2D Delaunay triangulation

View source: R/delaunay.R

plotDelaunay2DR Documentation

Plot 2D Delaunay triangulation

Description

Plot a constrained or unconstrained 2D Delaunay triangulation.

Usage

plotDelaunay2D(
  triangulation,
  col_edges = "black",
  col_borders = "red",
  col_constraints = "green",
  fillcolor = "distinct",
  hue = "random",
  luminosity = "light",
  lty_edges = par("lty"),
  lwd_edges = par("lwd"),
  lty_borders = par("lty"),
  lwd_borders = par("lwd"),
  lty_constraints = par("lty"),
  lwd_constraints = par("lwd"),
  ...
)

Arguments

triangulation

an output of delaunay without constraints (constraints=NULL) or with constraints

col_edges

the color of the edges of the triangles which are not border edges nor constraint edges; NULL for no color

col_borders

the color of the border edges; note that the border edges can contain the constraint edges for a constrained Delaunay tessellation; NULL for no color

col_constraints

for a constrained Delaunay tessellation, the color of the constraint edges which are not border edges; NULL for no color

fillcolor

controls the filling colors of the triangles, either NULL for no color, a single color, "random" to get multiple colors with randomColor, or "distinct" to get multiple colors with distinctColorPalette

hue, luminosity

if fillcolor = "random", these arguments are passed to randomColor

lty_edges, lwd_edges

graphical parameters for the edges which are not border edges nor constraint edges

lty_borders, lwd_borders

graphical parameters for the border edges

lty_constraints, lwd_constraints

in the case of a constrained Delaunay triangulation, graphical parameters for the constraint edges which are not border edges

...

arguments passed to points for the vertices, such as type="n" or asp=1

Value

No value, just renders a 2D plot.

See Also

mesh2d for an interactive plot

Examples

library(delaunay)
# random points in a square ####
square <- rbind(
  c(-1, 1), c(1, 1), c(1, -1), c(-1, -1)
)
library(uniformly)
set.seed(314)
ptsinsquare <- runif_in_cube(10L, d = 2L)
pts <- rbind(square, ptsinsquare)
d <- delaunay(pts)
opar <- par(mar = c(0, 0, 0, 0))
plotDelaunay2D(
  d, type = "n", xlab = NA, ylab = NA, axes = FALSE, asp = 1,
  fillcolor = "random", luminosity = "dark", lwd_borders = 3
)
par(opar)

# a constrained Delaunay triangulation: outer and inner hexagons ####
nsides <- 6L
angles <- seq(0, 2*pi, length.out = nsides+1L)[-1L]
outer_points <- cbind(cos(angles), sin(angles))
inner_points <- outer_points / 2
points <- rbind(outer_points, inner_points)
# constraint edges
indices <- 1L:nsides
edges <- cbind(
  indices, c(indices[-1L], indices[1L])
)
edges <- rbind(edges, edges + nsides)
# constrained Delaunay triangulation
d <- delaunay(points, constraints = edges)
opar <- par(mar = c(0, 0, 0, 0))
plotDelaunay2D(
  d, type = "p", pch = 19, xlab = NA, ylab = NA, axes = FALSE, asp = 1,
  fillcolor = "orange", lwd_borders = 3
)
par(opar)

# another constrained Delaunay tesselation: a face ####
V <- as.matrix(read.table(
  system.file("extdata", "face_vertices.txt", package = "delaunay")
))[, c(2L, 3L)]
E <- as.matrix(read.table(
  system.file("extdata", "face_edges.txt", package = "delaunay")
))[, c(2L, 3L)]
d <- delaunay(points = V, constraints = E)
opar <- par(mar = c(0, 0, 0, 0))
plotDelaunay2D(
  d, type = "n", xlab = NA, ylab = NA, axes = FALSE, asp = 1,
  fillcolor = "salmon", col_borders = "black",
  lwd_borders = 3, lwd_constraints = 2, lty_edges = "dashed"
)
par(opar)

delaunay documentation built on May 31, 2023, 6:26 p.m.