Click or drag to resize

Telogis.GeoBase.MathUtil

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release
MathUtil Namespace

Contains mathematical utility functions for manipulating spatial data.

Functions
NameDescription
bearing (LatLon from, LatLon to)

Finds the initial bearing that one would have to travel in to move in a straight line along a great-circle arc from one location to another.

JavaScript
var bearing = Telogis.GeoBase.MathUtil.bearing(
    new Telogis.GeoBase.LatLon(33.587137,-117.742878),
    new Telogis.GeoBase.LatLon(33.575037,-117.724762)
);
alert('Heading from->to is '+bearing+' degrees');
Arguments
  • from (LatLon) - The latitude-longitude coordinates to take the bearing from.

  • to (LatLon) - The latitude-longitude coordinates to take the bearing to.

Returns

Number - The bearing (degrees true) to initially travel in from MathUtil.bearing.from to MathUtil.bearing.to. That is, 0 degrees indicates direct north, 90 degrees due east, and so on.

bearingToCompass (Number bearing)

Finds the compass point represented by a certain bearing angle.

JavaScript
var bearing = 135;
var compass = Telogis.GeoBase.MathUtil.bearingToCompass(bearing);
alert(bearing+' degrees converts to a compass direction of '+compass);
Arguments
  • bearing (Number) - The bearing to convert to a compass direction, in degrees true (clockwise from north).

Returns

String - The compass direction closest to MathUtil.bearingToCompass.bearing. This may be any of "N", "NE", "E", "SE", "S", "SW", "W", or "NW".

clamp (Number x, Number minValue, Number maxValue)

Finds the closest value to a specified integer that falls within a specified range.

Arguments
  • x (Number) - The value to clamp.

  • minValue (Number) - The minimum value that can be returned.

  • maxValue (Number) - The maximum value that can be returned.

Returns

Number - If MathUtil.clamp.x lies between MathUtil.clamp.minValue and MathUtil.clamp.maxValue, the result is MathUtil.clamp.x. Otherwise, the result is MathUtil.clamp.minValue if MathUtil.clamp.x is less than MathUtil.clamp.minValue, or MathUtil.clamp.maxValue if MathUtil.clamp.x is greater than MathUtil.clamp.maxValue.

convertSpeedUnits (Number value, String fromUnits, String toUnits)

Converts between one kind of SpeedUnit and another.

JavaScript
var val = 10;
var conv = Telogis.GeoBase.MathUtil.convertSpeedUnits(
    val,
    Telogis.GeoBase.SpeedUnit.MilesPerHour,
    Telogis.GeoBase.SpeedUnit.KilometersPerHour
);
alert(val + ' mph equates to ' + conv + ' kmh');
Arguments
  • value (Number) - The value to convert.

  • fromUnits (String) - The string abbreviation of the type of units to convert from, which should be a SpeedUnit code.

  • toUnits (String) - The string abbreviation of the type of units to convert to, which should be a SpeedUnit code.

Returns

Number - MathUtil.convertSpeedUnits.value represented in MathUtil.convertSpeedUnits.toUnits.

convertTimeUnits (Number value, String fromUnits, String toUnits)

Converts between one kind of TimeUnit and another.

JavaScript
var val = 10;
var conv = Telogis.GeoBase.MathUtil.convertTimeUnits(
    val,
    Telogis.GeoBase.TimeUnit.MINUTES,
    Telogis.GeoBase.TimeUnit.SECONDS
);
alert(val + ' minutes equates to ' + conv + ' seconds');
Arguments
  • value (Number) - The value to convert.

  • fromUnits (String) - The string abbreviation of the type of units to convert from, which should be a TimeUnit code.

  • toUnits (String) - The string abbreviation of the type of units to convert to, which should be a TimeUnit code.

Returns

Number - MathUtil.convertTimeUnits.value represented in MathUtil.convertTimeUnits.toUnits.

convertUnits (Number value, String fromUnits, String toUnits)

Converts between one kind of DistanceUnit and another.

JavaScript
var val = 10;
var conv = Telogis.GeoBase.MathUtil.convertUnits(
    val,
    Telogis.GeoBase.DistanceUnit.MILES,
    Telogis.GeoBase.DistanceUnit.KILOMETERS
);
alert(val + ' Miles equates to ' + conv + ' Kilometers');
Arguments
  • value (Number) - The value to convert.

  • fromUnits (String) - The string abbreviation of the type of units to convert from, which should be a DistanceUnit code.

  • toUnits (String) - The string abbreviation of the type of units to convert to, which should be a DistanceUnit code.

Returns

Number - MathUtil.convertUnits.value represented in MathUtil.convertUnits.toUnits.

displace (LatLon from, Number dist, Number bearing, String units)

Constructs the coordinate point that is located at a displacement of a certain distance (along a shortest great-circle arc) and bearing from a given LatLon.

JavaScript
//    Locate a point 10 miles from the specified LatLon at a bearing
//    of 90 degrees
var displace = Telogis.GeoBase.MathUtil.displace(
    new Telogis.GeoBase.LatLon(33.587137,-117.742878),
    10,
    90,
    Telogis.GeoBase.DistanceUnit.MILES
);
alert(displace);
Arguments
  • from (LatLon) - The latitude-longitude coordinate point to perform the displacement calculation from.

  • dist (Number) - The distance from MathUtil.displace.from, in the specified MathUtil.displace.units, to construct the second location from.

  • bearing (Number) - The bearing relative to MathUtil.displace.from, in degrees true, to construct the second location at.

  • units (String) - The string abbreviation of the units that MathUtil.displace.dist is specified in, which should be a DistanceUnit code.

Returns

LatLon - A new LatLon location the specified distance from MathUtil.displace.from and at the specified bearing relative to it.

distance (LatLon from, LatLon to, String units)

Finds the distance covered by traveling in a great-circle from one latitude-longitude location to another, in the specified units.

JavaScript
var dist = Telogis.GeoBase.MathUtil.distance(
    new Telogis.GeoBase.LatLon(33.587137,-117.742878),
    new Telogis.GeoBase.LatLon(33.575037,-117.724762),
    Telogis.GeoBase.DistanceUnit.KILOMETERS
);
alert('Point-to-point distance is ' + dist + ' Kilometers');
Arguments
  • from (LatLon) - The location to measure the distance from.

  • to (LatLon) - The location to measure the distance to.

  • (Optional) units (String) - The string abbreviation of the units that the calculated distance should be given in, which should be a DistanceUnit code. Defaults to DistanceUnit.MILES.

Returns

Number - The great-circle distance of MathUtil.distance.to from MathUtil.distance.from, measured in MathUtil.distance.units.

positiveModulo (Number value, Number base)

Finds the positive modulo value of a given number with respect to a certain base. This differs from the built-in modulo operation in that using the % will return a negative number when used with negative values.

Arguments
  • value (Number) - The value to take the modulo of.

  • base (Number) - The base of the modulo operation.

Returns

Number - The smallest positive number congruent to MathUtil.positiveModulo.value, relative to MathUtil.positiveModulo.base.

toDegrees (Number radians)

Converts an angle from radians to degrees.

Arguments
  • radians (Number) - The value of the angle in radians.

Returns

Number - MathUtil.toDegrees.radians represented in degrees.

toRadians (Number degrees)

Converts an angle from degrees to radians.

Arguments
  • degrees (Number) - The value of the angle in degrees.

Returns

Number - MathUtil.toRadians.degrees represented in radians.