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 point1Mapspace.Coordinate First point.
point2Mapspace.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 anumber First value
bnumber Value to check
cnumber 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 coordsCesium.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 xnumber Coord X.
ynumber Coord Y.
nnumber Normalization.
resultArray.<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 valuenumber Number to limit.
minnumber Minimum value.
maxnumber 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 anglenumber Angle to clamp.
isRadianboolean <optional>
If the passed angle is a radian. If it is omited the angle param is considered decimal.
toPIboolean <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.
toRadianboolean <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 extent1Mapspace.Extent The extent that will be modified.
extent2Mapspace.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 numnumber Number to move.
decnumber 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 anumber First double.
bnumber Second double.
epsilonnumber <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-->xParameters:
Name Type Description ynumber Coordinate Y.
znumber Coordinate Z.
xnumber 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 valuesArray.<number> Values.
minnumber Minimum value.
maxnumber Maximum value.
nclassesnumber 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 coordinatesArray.<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 coordinate1Mapspace.Coordinate Coordinate as longitude and latitude, i.e. an array with longitude as 1st and latitude as 2nd element.
coordinate2Mapspace.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 coordinatesArray.<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 aMapspace.Coordinate First coordinate of the segment.
bMapspace.Coordinate Second coordinate of the segment.
cMapspace.Coordinate Coordinate to check.
tolerancenumber <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 longitudenumber Longitude of the coordinate we want to transform.
latitudenumber Longitude of the coordinate we want to transform.
elevnumber 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 longitudenumber Longitude in WGS84 degrees.
latitudenumber Latitude in WGS84 degrees.
distancenumber 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 coordsArray.<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 breaksArray.<number> Breaks.
symmetryPointnumber Symmetry point.
astridebool 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 frictionnumber Friction.
velocityXnumber Velocity in X coord.
velocityYnumber Velocity in Y coord.
maxFrictionTimenumber Maximum friction time.
resultArray.<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 coordsMapspace.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 dividendnumber Dividend.
divisornumber 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 valuesArray.<number> Values.
minnumber Minimum value.
maxnumber Maximum value.
nclassesnumber 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 valuesArray.<number> Values.
minnumber Minimum value.
maxnumber Maximum value.
nclassesnumber 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 valuesArray.<number> Values.
minnumber Minimum value.
maxnumber Maximum value.
nclassesnumber 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 valuenumber 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_firstArray.<number> First segment with two coordinates.
seg_secondArray.<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 valuesArray.<number> Values.
minnumber Minimum value.
maxnumber Maximum value.
nclassesnumber Number of classes.
opt_labelsArray.<string> <nullable>
An optional array in which store the default labels for the breaks.
- Source:
- mapspace/math/math.js
Returns:
- Type
- Array.<number>