This namespace contains definitions for static functions that make it easy some math calculations.
- Source:
- mapspace/math/math.jsdoc
Methods
-
<static> bearing(point1, point2)
-
Calculates the bearing between two points in lonlat EPSG:4326 projection. The bearing is calculated at the first point and in decimal degrees. Inspired by: https://www.movable-type.co.uk/scripts/latlong.html
Parameters:
Name Type Description point1
Mapspace.Coordinate First point.
point2
Mapspace.Coordinate Second point.
- Source:
- mapspace/math/math.js
Returns:
- Type
- number
-
<static> between(a, b, c)
-
It checks if b is between a and c.
Parameters:
Name Type Description a
number First value
b
number Value to check
c
number Second value
- Source:
- mapspace/math/math.js
Returns:
- Type
- boolean
-
<static> cartesianToMercator(coords)
-
Reprojects a cartesian 3D point or points to mercator coordinates with elevation in meters.
Parameters:
Name Type Description coords
Cesium.Cartesian3 | Array.<Cesium.Cartesian3> Cartesian 3D point used in Cesium viewer (ECEF).
- Source:
- mapspace/math/math.js
Returns:
- Type
- Mapspace.Coordinate | Array.<Mapspace.Coordinate>
-
<static> changeVectorNorm(x, y, n, result)
-
Changes the vector normal.
Parameters:
Name Type Description x
number Coord X.
y
number Coord Y.
n
number Normalization.
result
Array.<number> The two values of the result.
- Source:
- mapspace/math/math.js
-
<static> clamp(value, min, max)
-
Return a value between limits.
Parameters:
Name Type Description value
number Number to limit.
min
number Minimum value.
max
number Maximum value.
- Source:
- mapspace/math/math.js
Returns:
Limited value.
- Type
- number
-
<static> clampAngle(angle [, isRadian] [, toPI] [, toRadian])
-
Return a decimal degree clamped to [0.0, 360.0) or [-180.0, 180.0] values, or their equivalent in radians.
Parameters:
Name Type Argument Description angle
number Angle to clamp.
isRadian
boolean <optional>
If the passed angle is a radian. If it is omited the angle param is considered decimal.
toPI
boolean <optional>
If the returned value must be clamped to [-180.0, 180.0]. If it is omited angles are returned in [0.0, 360.0) range.
toRadian
boolean <optional>
If returned value must be radians. If omited returns decimal degrees.
- Source:
- mapspace/math/math.js
Returns:
Angle clampled.
- Type
- number
-
<static> clampExtent(extent1, extent2)
-
Return a clamped extent. Extent1 is modified so its values do not exceed the values of extent2.
Parameters:
Name Type Description extent1
Mapspace.Extent The extent that will be modified.
extent2
Mapspace.Extent The extent that will be used as maximum.
- Source:
- mapspace/math/math.js
Returns:
Returns a reference to the extent1 param, once modified.
- Type
- Mapspace.Extent
-
<static> decreaseAbs(num, dec)
-
Moves a value towards zero value.
Parameters:
Name Type Description num
number Number to move.
dec
number Quantity to move towards zero.
- Source:
- mapspace/math/math.js
Returns:
Zero or the new value.
- Type
- number
-
<static> doubleNear(a, b, epsilon)
-
Compare two doubles (but allow some difference).
Parameters:
Name Type Argument Description a
number First double.
b
number Second double.
epsilon
number <nullable>
Optional maximum difference allowable between doubles.
- Source:
- mapspace/math/math.js
Returns:
- Type
- boolean
-
<static> ECEFToLatLon(y, z, x)
-
Transforms one coordinate in ECEF to geographic projection. Relation between threejs and ECEF ThreeJS --> x, y, z ECEF --> y, z, x
|y-->z | | | +---------- / x-->y / / / z-->x
Parameters:
Name Type Description y
number Coordinate Y.
z
number Coordinate Z.
x
number Coordinate X.
- Source:
- mapspace/math/math.js
Returns:
Coordinate as [longitude, latitude, elev].
- Type
- Mapspace.Coordinate
-
<static> equalInterval(values, min, max, nclasses)
-
Returns the list of breaks of a set of values through equal intervals. Based on: https://github.com/qgis/QGIS/tree/master/src/core/classification
Parameters:
Name Type Description values
Array.<number> Values.
min
number Minimum value.
max
number Maximum value.
nclasses
number Number of classes.
- Source:
- mapspace/math/math.js
Returns:
- Type
- Array.<number>
-
<static> getDistance(coordinates)
-
Return the total distance of the linestring given by its coordinates.
Parameters:
Name Type Description coordinates
Array.<Mapspace.Coordinate> The coordinates.
- Source:
- mapspace/math/math.js
Returns:
The distance.
- Type
- number
-
<static> getDistanceOnEarth(coordinate1, coordinate2)
-
Calculates distance in meters from one point to other of Earth. Calculation is aproximated using mean radius spherical Earth.
Parameters:
Name Type Description coordinate1
Mapspace.Coordinate Coordinate as longitude and latitude, i.e. an array with longitude as 1st and latitude as 2nd element.
coordinate2
Mapspace.Coordinate Coordinate as longitude and latitude, i.e. an array with longitude as 1st and latitude as 2nd element.
- Source:
- mapspace/math/math.js
Returns:
Distance in meters.
- Type
- number
-
<static> getTopCoordinate(coordinates)
-
Return the coordinate with the top Z value. Coordinates are in local space, so the Z value are Y values (as in WebGL).
Parameters:
Name Type Description coordinates
Array.<Mapspace.Coordinate> The local coordinates.
- Source:
- mapspace/math/math.js
Returns:
The coordinate.
- Type
- Mapspace.Coordinate
-
<static> isOnSegment(a, b, c, tolerance)
-
Checks if coordinate c is in segment between a and b.
Parameters:
Name Type Argument Description a
Mapspace.Coordinate First coordinate of the segment.
b
Mapspace.Coordinate Second coordinate of the segment.
c
Mapspace.Coordinate Coordinate to check.
tolerance
number <nullable>
Optional max distance tolerance. By default is 1.
- Source:
- mapspace/math/math.js
Returns:
- Type
- boolean
-
<static> latLonToECEF(longitude, latitude, elev)
-
Transforms one coordinate in geographical projection to ECEF.
Parameters:
Name Type Description longitude
number Longitude of the coordinate we want to transform.
latitude
number Longitude of the coordinate we want to transform.
elev
number Elevation.
- Source:
- mapspace/math/math.js
Returns:
Coordinate as [x, y, z].
- Type
- Mapspace.Coordinate
-
<static> latLonToExtent(longitude, latitude, distance)
-
Returns an extent in WGS84 given a geographical coordinate and a distance in meters.
Parameters:
Name Type Description longitude
number Longitude in WGS84 degrees.
latitude
number Latitude in WGS84 degrees.
distance
number Distance in meters.
- Source:
- mapspace/math/math.js
Returns:
- Type
- Mapspace.Extent
-
<static> lineSelfIntersects(coords)
-
Checks if there is intersection in a polygon. It can't check polygons with 3 segments.
Parameters:
Name Type Description coords
Array.<Mapspace.Coordinate> Coordinates.
- Source:
- mapspace/math/math.js
Returns:
- Type
- boolean
-
<static> makeBreaksSymmetric(breaks, symmetryPoint, astride)
-
Make a list of breaks symmetric around a point.
Parameters:
Name Type Description breaks
Array.<number> Breaks.
symmetryPoint
number Symmetry point.
astride
bool Remove symmetry point or not.
- Source:
- mapspace/math/math.js
Returns:
- Type
- Array.<number>
-
<static> maxFriction(friction, velocityX, velocityY, maxFrictionTime, result)
-
Calculates the maximum friction.
Parameters:
Name Type Description friction
number Friction.
velocityX
number Velocity in X coord.
velocityY
number Velocity in Y coord.
maxFrictionTime
number Maximum friction time.
result
Array.<number> The two values of the result.
- Source:
- mapspace/math/math.js
-
<static> mercatortoCartesian(coords)
-
Reprojects mercator coordinates to cartesian 3D points.
Parameters:
Name Type Description coords
Mapspace.Coordinate | Array.<Mapspace.Coordinate> Mercator coordinates. They can have elevation or not. If not a 0.0 elevation is used.
- Source:
- mapspace/math/math.js
Returns:
- Type
- Cesium.Cartesian3 | Array.<Cesium.Cartesian3>
-
<static> mod(dividend, divisor)
-
Modulo operation
Parameters:
Name Type Description dividend
number Dividend.
divisor
number Divisor.
- Source:
- mapspace/math/math.js
Returns:
Value in range
[0,divisor[
- Type
- number
-
<static> naturalBreaks(values, min, max, nclasses)
-
Returns the list of breaks of values through natural breaks (Jenks). Based on: https://github.com/qgis/QGIS/tree/master/src/core/classification
Parameters:
Name Type Description values
Array.<number> Values.
min
number Minimum value.
max
number Maximum value.
nclasses
number Number of classes.
- Source:
- mapspace/math/math.js
Returns:
- Type
- Array.<number>
-
<static> prettyBreaks(values, min, max, nclasses)
-
Returns the list of breaks of values through pretty breaks. Based on: https://github.com/qgis/QGIS/tree/master/src/core/classification
Parameters:
Name Type Description values
Array.<number> Values.
min
number Minimum value.
max
number Maximum value.
nclasses
number Number of classes.
- Source:
- mapspace/math/math.js
Returns:
- Type
- Array.<number>
-
<static> quantile(values, min, max, nclasses)
-
Returns the list of breaks of values through quantiles (equal count). Based on: https://github.com/qgis/QGIS/tree/master/src/core/classification
Parameters:
Name Type Description values
Array.<number> Values.
min
number Minimum value.
max
number Maximum value.
nclasses
number Number of classes.
- Source:
- mapspace/math/math.js
Returns:
- Type
- Array.<number>
-
<static> real(value)
-
Checks if a value is a real number. Not NaN or Infinity.
Parameters:
Name Type Description value
number Number to check.
- Source:
- mapspace/math/math.js
Returns:
True if number is a real number.
- Type
- boolean
-
<static> segmentIntersects(seg_first, seg_second)
-
Detects if two segments intersects in 2D. Each segment is defined by four values, the first pair for the coordinates of the initial point of the segment and the last pair for the coordinates of the final point of the segment.
Parameters:
Name Type Description seg_first
Array.<number> First segment with two coordinates.
seg_second
Array.<number> Second segment with two coordinates.
- Source:
- mapspace/math/math.js
Returns:
True or false if there is not intersection.
- Type
- boolean
-
<static> standardDeviation(values, min, max, nclasses, opt_labels)
-
Returns the list of breaks of values through standard deviation. Based on: https://github.com/qgis/QGIS/tree/master/src/core/classification
Parameters:
Name Type Argument Description values
Array.<number> Values.
min
number Minimum value.
max
number Maximum value.
nclasses
number Number of classes.
opt_labels
Array.<string> <nullable>
An optional array in which store the default labels for the breaks.
- Source:
- mapspace/math/math.js
Returns:
- Type
- Array.<number>