MathUtil

object MathUtil

Utility functions that are used my both PolyUtil and SphericalUtil.

Properties

Link copied to clipboard
const val EARTH_RADIUS: Double

The earth's radius, in meters. Mean radius as defined by IUGG.

Functions

Link copied to clipboard

Computes inverse haversine. Has good numerical stability around 0. arcHav(x) == acos(1 - 2 * x) == 2 * asin(sqrt(x)). The argument must be in 0, 1, and the result is positive.

Link copied to clipboard
fun clamp(x: Double, low: Double, high: Double): Double

Restrict x to the range low, high.

Link copied to clipboard

Returns haversine(angle-in-radians). hav(x) == (1 - cos(x)) / 2 == sin(x / 2)^2.

Link copied to clipboard
fun havDistance(lat1: Double, lat2: Double, dLng: Double): Double

Returns hav() of distance from (lat1, lng1) to (lat2, lng2) on the unit sphere.

Link copied to clipboard
Link copied to clipboard

Returns latitude from mercator Y.

Link copied to clipboard

Returns mercator Y corresponding to latitude. See http://en.wikipedia.org/wiki/Mercator_projection .

Link copied to clipboard

Returns the non-negative remainder of x / m.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun wrap(n: Double, min: Double, max: Double): Double

Wraps the given value into the inclusive-exclusive interval between min and max.