as_polygon2d() casts to a Polygon2D object.
Usage
as_polygon2d(x, ...)
# S3 method for class 'Coord2D'
as_polygon2d(x, convex = NA, ...)
# S3 method for class 'Polygon2D'
as_polygon2d(x, convex = NA, ...)
# S3 method for class 'numeric'
as_polygon2d(x, y = 0, convex = NA, ...)
# S3 method for class 'Ellipse2D'
as_polygon2d(x, n = 60L, type = c("inner", "outer"), ...)Arguments
- x
Object to cast. Either a Coord2D object of vertices or a numeric vector of x-coordinates.
- ...
Ignored; only included for S3 method consistency.
- convex
NAto auto-detect (default),TRUEto assert convex,FALSEto mark as concave.- y
Numeric vector of y-coordinates (used when
xis numeric).- n
Number of vertices in the approximating polygon (default
60L).- type
"inner"(default) for an inscribed polygon whose vertices lie on the ellipse, or"outer"for a circumscribed polygon whose edges are tangent to the ellipse. Both polygons are convex.
Value
A Polygon2D object.
See also
isotoxal_2ngon_polygon2d() and regular_ngon_polygon2d() to
directly construct common polygon shapes.
Examples
vertices <- as_coord2d(x = c(0, 1, 1, 0), y = c(0, 0, 1, 1))
p <- as_polygon2d(vertices)
p$is_convex
#> [1] TRUE
print(p)
#> <Polygon2D[4 vertices, convex = TRUE]>
#> x y w
#> [1,] 0 0 1
#> [2,] 1 0 1
#> [3,] 1 1 1
#> [4,] 0 1 1
plot(p)
