Calculate the centroid (center of mass) of a shape.
Value
If
xis a single matrix: returns a numeric vector of length 2 (x, y coordinates)If
xis a list: returns a list of numeric vectorsIf
xis a tibble: returns a list of numeric vectors extracted from coo column
Details
For tibbles, this function extracts centroid values without modifying the tibble.
Use within mutate() to add as a column: mutate(df, cent = get_centroid(coo))
See also
coo_center() for centering shapes
Examples
get_centroid(shapes$cat)
#> [1] 188.125 94.200
get_centroid(shapes)
#> $cat
#> [1] 188.125 94.200
#>
#> $dog
#> [1] 206.9750 127.0917
#>
#> $heart
#> [1] 201.6417 142.3500
#>
#> $leaf2
#> [1] 195.425 125.650
#>
# Extract from tibble
centroids <- get_centroid(bot)
# Add to tibble
bot$centroid <- get_centroid(bot)
