sl.centroid | R Documentation |
Compute the centroid (barycenter) of a polygon on a unit sphere. The locations of the vertices need to be provided in lon-lat coordinates.
sl.centroid(stamp.lon, stamp.lat, ref.lon = NA, ref.lat = NA)
stamp.lon |
a vector of length >= 3 with the longitudes of the polygon vertices. |
stamp.lat |
a vector of the same length as |
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. |
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.
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). |
Use this function with caution: it appears that the method is imprecise for large polygons where the curvature of the sphere is not negligible.
Helge Goessling
sl.barycenter
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.