compute_polygon_centroid: Compute polygon centroid

Description Usage Arguments Value Author(s) Examples

View source: R/compute-polygon-centroid.R

Description

This function takes in a data frame containing one or more polygons, and computes the centroid (geometric center) of each polygon.

Usage

1

Arguments

vertex.df

A data frame where each row corresponds to the vertex of a polygon. It must contain the columns x, y, and optionally group (must be integer). x and y specify the coordinates of the vertex, and group is used to indicate which polygon the vertex belongs to. If vertex.df contains only a single polygon, group can be omitted.

Value

A data frame that contains three columns:

group

The group number of the polygon

x, y

The coordinates of the centroid

Author(s)

Mathias Isaksen mathiasleanderi@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Example with multiple polygons
vertex.df = compute_regular_polygons(
 center = data.frame(x = c(0, 10), y = c(0, 0)),
 radius = 1,
 num.edges = c(4, 1000)
)
centroid.df = compute_polygon_centroid(vertex.df)

# Centroids should be (0, 0) and c(10, 0)
print(centroid.df)

mathiasisaksen/artKIT documentation built on Dec. 21, 2021, 2:52 p.m.