sl.barycenter: Compute Barycenter of Points

View source: R/sl.barycenter.R

sl.barycenterR Documentation

Compute Barycenter of Points

Description

Compute the barycenter of points on a unit sphere. The locations of the points can be provided in x-y-z or lon-lat coordinates. Can be used directly to compute the barycenter (centroid) of a triangle using its vertices, but NOT FOR POLYGONS WITH MORE THAN 3 VERTICES! To that end, use sl.centroid.

Usage

sl.barycenter(x = NULL, y = NULL, z = NULL, lon = NULL, lat = NULL, weights = NULL, rm.na = TRUE)

Arguments

x

a vector of arbitrary length with the x-coordinates of the points on the unit sphere. If specified, lon and lat are ignored.

y

a vector of the same length as x with the y-coordinates of the points on the unit sphere. Used only if x is specified.

z

a vector of the same length as x with the z-coordinates of the points on the unit sphere. Used only if x is specified.

lon

a vector of arbitrary length with the longitudes of the points. Used only if x is not specified.

lat

a vector of the same length as lon with the latitudes of the points. Used only if x is not specified.

weights

a vector of the length corresponding to the number of points with optional weights of the points.

rm.na

a logical values specifying whether or not to remove NAs. Default is TRUE. If FALSE and NAs are present, the result will be NA.

Details

The computation is based on the x-y-z locations of the points. The directly resulting barycenter is located within the unit sphere and projected from the origin back onto the unit sphere.

Value

lon

longitude of the barycenter

lat

latitude of the barycenter

Author(s)

Helge Goessling

See Also

sl.centroid

Examples

## Using x-y-z as input:
sl.barycenter(x=c(1,0,0),y=c(0,1,0),z=c(0,0,1))

## Using lon-lat as input:
sl.barycenter(lon=c(0,90,0),lat=c(0,0,90))

## Both should return:
## $lon
## [1] 45
## 
## $lat
## [1] 35.26439


FESOM/spheRlab documentation built on July 13, 2024, 7 a.m.