sl.points2ellipse: Draw Ellipse around Points on a Sphere

sl.points2ellipseR Documentation

Draw Ellipse around Points on a Sphere

Description

Draw an ellipse representing the cumulative distribution function of a bivariate normal distribution fitted to points on a sphere based on the covariance matrix.

Usage

sl.points2ellipse <- function (lon = NULL, lat = NULL, prob.within = 0.95, npoints = 360, return.ellispecs = F, Rsphere = 1)

Arguments

lon

a numeric vector specifying the longitudes of the points.

lat

a numeric vector specifying the latitudes of the points.

prob.within

a numeric scalar specifying the integrated probability to be enclosed by the ellipse.

npoints

an integer scalar specifying the number of points comprising the border of the ellipse.

return.ellispecs

a logical value specifying if area and semi-major and -minor axis of the resulting ellipse should be returned.

Rsphere

a numeric scalar defining the radius of the sphere, needed for calculating the area of the ellipse, default is Rsphere = 1. The units for the semi-axes will correspond to the units of Rsphere.

Details

The points are rotated so that their barycenter is the new pole. Then, the function ellipse from the package mixtools is used to derive the ellipse on the xy-plane. Finally, the points are projected back onto the sphere with x,y fixed.

The latter implies that a very large ellipse obtained due to a large prob.within or due to excessive spread of the point cloud (e.g., spanning more than one hemisphere) will cause an error. However, in that case the assumptions underlying in the projection from the sphere to the xy-plane and back are violated too heavily anyway.

Note that the area of the ellipse is calculated in the projection on the xy-plane, i.e. the curvature is ignored.

Value

A list with the following elements:

lon

a numeric vector giving the longitudes of the points describing the ellipse

lat

a numeric vector giving the longitudes of the points describing the ellipse

area

a numeric scalar giving the area of the ellipse - only if return.ellispecs = TRUE

a, b

numeric scalars for semi-major and semi-minor axis length - only if return.ellispecs = TRUE

Author(s)

Helge Goessling, modified by Simon Reifenberg

See Also

mixtools::ellipse

Examples

lon0 = rnorm(100,sd=15)
lat0 = rnorm(100,sd=5)
angle = pi/6
lon = lon0 * cos(angle) - lat0 * sin(angle)
lat = lon0 * sin(angle) + lat0 * cos(angle)

res = sl.points2ellipse(lon=lon,lat=lat,prob.within=0.9)

plot(lon,lat)
lines(res$lon,res$lat,col="red")

FESOM/spheRlab documentation built on April 6, 2024, 6:52 p.m.