Description Usage Arguments Details Value Examples
This function wraps RTriangle::triangulate()
to make it easier to
call for my use case, and returns results appropriate for plotting in
ggplot2
.
1 | decompose(polygons_df)
|
polygons_df |
polygon data.frame with |
By combining polyclip
and RTriangle
packages, this package
will successfully decompose into triangles the following polygon types:
Simple polygons
Polyons with holes
Multiple polygons with holes
Polygons with self-intersection
Polygons with duplicated vertices
data.frame with x
, y
coordinates of the vertices of the
resulting triangles. Also includes idx
numbering the triangles.
1 2 3 4 5 6 7 8 9 10 11 12 13 | ## Not run:
# Polygon with a hole
polygons_df <- df <- data.frame(
x = c(4, 8, 8, 4, 6, 7, 7, 6),
y = c(4, 4, 8, 8, 6, 6, 7, 7),
group = c(1, 1, 1, 1, 1, 1, 1, 1),
subgroup = c(1, 1, 1, 1, 2, 2, 2, 2)
)
triangles_df <- triangular::decompose(polygons_df)
ggplot(triangles_df) +
geom_polygon(aes(x, y, fill = as.factor(idx)))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.