An ngon is a regular polygon, meaning that each side is of equal length. The ob_ngon object can be specified with a center, n (number of sides), radius, and angle. Instead of specifying a radius, one can specify either the side_length or the length of the apothem (i.e., the distance from the center to a side's midpoint.
Usage
ob_ngon(
center = ob_point(0, 0),
n = 3L,
radius = numeric(0),
angle = 0,
label = character(0),
side_length = numeric(0),
apothem = numeric(0),
vertex_radius = numeric(0),
alpha = numeric(0),
color = character(0),
fill = character(0),
linewidth = numeric(0),
linetype = numeric(0),
style = S7::class_missing,
x = numeric(0),
y = numeric(0),
id = character(0),
...
)Arguments
- center
point at center of the ngon
- n
Number of sides
- radius
Distance from center to a vertex
- angle
Angle of rotation for ngon
- label
A character, angle, or label object
- side_length
Distance of each side (can be used instead of radius to set size of ngon)
- apothem
Distance from center to a side's midpoint (can be used instead of the radius to set size of ngon)
- vertex_radius
A numeric or unit vector of length one, specifying the corner radius
- alpha
numeric value for alpha transparency
- color
character string for color
- fill
character string for fill color
- linewidth
Width of lines
- linetype
type of lines
- style
Gets and sets the styles associated with
ob_ngon- x
x-coordinate of center point. If specified, overrides x-coordinate of
@center.- y
x-coordinate of center point. If specified, overrides y-coordinate of
@center.- id
character string to identify object
- ...
<
dynamic-dots> properties passed to style
Additional properties
@aestheticsA list of information about the object's aesthetic properties
@areaThe area of the ngons in the
ob_ngonobject@bounding_boxa rectangle that contains all the ngons
@circumscribedReturns the circle that circumscribes the ngon.
@inscribedReturns the circle that inscribes the ngon.
@lengthThe number of ngons in the
ob_ngonobject@normal_atA function that finds a point that is perpendicular from the ngon and at a specified distance
@perimeterThe length of the sum of all the side segments
@point_atA function that finds a point on the ngon at the specified angle.
@segmentsside segments of the regular polygon
@tangent_atA function that finds the tangent line at the specified angle.
@tibbleGets a tibble (data.frame) containing parameters and styles used by
ggforce::geom_shape.@verticespoints on the regular polygon
@eastright point (
ob_point)@northtop point (
ob_point)@westleft point (
ob_point)@southtop point (
ob_point)@northeastupper right point (
ob_point)@northwestupper left point (
ob_point)@southwestlower left point (
ob_point)@southeastlower right point (
ob_point)
Examples
ggdiagram() +
ob_ngon(center = ob_point(x = 3:8, y = 0),
n = 3:8,
radius = .4)
# Size can be set with side_length instead of radius
ggdiagram() +
ob_ngon(center = ob_point(x = 3:8, y = 0),
n = 3:8,
side_length = .4)
# Size can be set with apothem (distance from center to side's midpoint)
ggdiagram() +
ob_ngon(n = 4,
radius = 1,
fill = NA,
color = "blue") +
ob_ngon(n = 4,
apothem = 1,
fill = NA,
color = "red") +
ob_circle(radius = 1)
# Getting the circles that inscribe and circumscribe the ngon
ggdiagram() +
{x <- ob_ngon(fill = NA, color = "black")} +
x@inscribed |> set_props(color = "blue") +
x@circumscribed |> set_props(color = "red")
