sl.centroid: Compute Centroid of a Polygon

View source: R/sl.centroid.R

sl.centroidR Documentation

Compute Centroid of a Polygon

Description

Compute the centroid (barycenter) of a polygon on a unit sphere. The locations of the vertices need to be provided in lon-lat coordinates.

Usage

sl.centroid(stamp.lon, stamp.lat, ref.lon = NA, ref.lat = NA)

Arguments

stamp.lon

a vector of length >= 3 with the longitudes of the polygon vertices.

stamp.lat

a vector of the same length as stamp.lon with the latitudes of the polygon vertices.

ref.lon

Scalar longitude of a point from which to decompose the polygon into triangles. If not specified, the barycenter of the polygon vertices is used.

ref.lat

Scalar latitude of a point from which to decompose the polygon into triangles. If not specified, the barycenter of the polygon vertices is used.

Details

The polygon is decomposed into triangles formed by any two neighboring vertices and one reference point. If not specified, the barycenter of all polygon vertices is used as reference point. For each triangle the centroid is computed using sl.barycenter and a weight proportional to the triangle size is assigned. If the direction of rotation around the refrence point is clockwise for a pair of polygon vertices, a negative weight is assigned. The polygon centroid is then computed as the weighted barycenter of the triangle centroids using sl.barycenter. Note that the overall direction of rotation (the order in which the polygon vertices are provided) does not affect the result because of the internal division by the sum of all weights.

Value

lon

Longitude of the centroid

lat

Latitude of the centroid

zeroweights

Number of triangles that were assigned zero weight

negweights

Number of triangles that were assigned a negative weight (due to clockwise rotation).

Note

Use this function with caution: it appears that the method is imprecise for large polygons where the curvature of the sphere is not negligible.

Author(s)

Helge Goessling

See Also

sl.barycenter

Examples

sl.centroid(stamp.lon=c(0,3,4,1.2),stamp.lat=c(-2,1,4,3.5))
## Should return:
## $lon
## [1] 1.905576
## 
## $lat
## [1] 1.592651
## 
## $zeroweights
## [1] 0
## 
## $negweights
## [1] 0

helgegoessling/spheRlab documentation built on April 8, 2024, 8:34 a.m.