View source: R/utils_polygon.R
poly_width_at | R Documentation |
The function computes the polygonal convex hull of the points in x and then returns the number of points that lie below a specified set of heights along the vertical axis of the convex hull.
poly_width_at(
x,
at = c(0.05, 0.25, 0.5, 0.75, 0.95),
unify = FALSE,
plot = FALSE
)
x |
A vector containing two-dimensional data points (often produced with object_contour). |
at |
A vector of heights along the vertical axis of the convex hull at
which to count the number of points below. The default value is |
unify |
A logical value indicating whether to use the unified convex hull calculation method. If unify = TRUE, coordinates in x will be first bound before computing the convex hull. |
plot |
A logical value that specifies whether the widths should be plotted. |
The convex hull computed from x is aligned along the major axis and then converted to a binary image. For each height in the at vector, the function computes the corresponding row number in the binary image (i.e., the row number that corresponds to the specified height along the vertical axis of the convex hull) and sums the values in that row to obtain the number of points that lie below the specified height. If the convex hull contains multiple polygons and unify = FALSE, the function loops over each polygon and returns a list of the number of points below the specified heights for each polygon. If the convex hull contains only one polygon or multiple polygons and unify = TRUE, the function returns a vector of the number of points below the specified heights for that single polygon.
A vector with the widths of the convex hull at the specified heights or a list of vectors with the widths of each component.
cont <- contours[[2]]
plot_polygon(cont |> conv_hull() |> poly_align())
# width below 5th, 25th, 50th, 75th, and 95th percentiles of the length
wd <- poly_width_at(cont)
wd
# width along the height
poly_width_at(cont, at = "height", plot = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.