Class Miscellaneous

This section is to describe various miscellaneous methods used as helpers for various things. This is not an object, so the methods here can be called on their own. (Note that the Math.xxx methods extend the Math prototype, however, and must use the Math. prefix).


Method Summary

isArray ( arg )
Determines if the argument is an array
radians ( degrees )
Converts degrees to radians
degrees ( radians )
Converts radians to degrees
normalize ( lon )
Normalizes a longitude value to be within -180 to 180
constrainLat ( lat )
Constrains a latitude to be within -90 to 90
greatCircleLat ( lat0 , lon0 , lat1 , lon1 , lon2 )
Given two coordinates and a third longitude, Calculates the latitude value of the third point so that all 3 points lie along the same great circle.
Math.sinh ( angle )
Calculates the hyperbolic sine of an angle
Math.cosh ( angle )
Calculates the hyperbolic cosine of an angle
Math.nint ( value , round )
Converts a number to an integer, with optional rounding.
Math.sqrDist ( pt1 , pt2 )
Calculates the square of the distance between two points

Method Detail

isArray

Determines if the argument is an array


Parameters
arg - Any single argument

Returns
True if the argument is an array, false if it is not

Examples
var yes = isArray(new Array(3));  // returns true
var no = isArray(3); // returns false

Notes


radians

Converts degrees to radians


Parameters
degrees - A value in degrees

Returns
A value in radians

Examples
var twopi = radians(360);
// Converts 360 degrees to its radian equivalent, = 2*pi

Notes


degrees

Converts radians to degrees


Parameters
radians - A value in radians

Returns
A value in degrees

Examples
var threesixty = degrees(2*3.14159);
// Converts two pi to its degree equivalent, = 360

Notes


normalize

Normalizes a longitude value to be within -180 to 180


Parameters
lon - A longitude value, or an array with a longitude value at element [0]

Returns
True, if lon is an array; the normalized value will be returned in element[0] of the array instead. False if lon is an invalid argument. Otherwise, the return value is the normalized value of lon.

Examples
lon1 = 185; lon2 = normalize(lon1);
// lon2 will have the value -175
lona[0] = 185; status = normalize(lona);
// lona[0] will be overwritten with -175, status will be true
err = normalize('hi');
// err will be false

Notes


constrainLat

Constrains a latitude to be within -90 to 90


Parameters
lat - A latitude value

Returns
The latitude constrained to -90 through 90

Examples
lon1 = constrainLat(50);  // lon1 will be 50
lon2 = constrainLat(100); // lon2 will be 90

Notes
All that is done here is that values that are out of bounds will be pushed back to the edge of the bounds.


greatCircleLat

Given two coordinates and a third longitude, Calculates the latitude value of the third point so that all 3 points lie along the same great circle.


Parameters
lat0 - The latitude value of the first point
lon0 - The longitude value of the first point
lat1 - The latitude value of the second point
lon1 - The longitude value of the second point
lon2 - The longitude value of the third point

Returns
The latitude value of the third point

Examples
lat3 = greatCircleLat(30,30, 40,40, 50);
// Calculates lat3 so it will be along the same great circle
// as 30,30 and 40,40 at the place where the great circle
// intersects longitude 50

Notes


Math.sinh

Calculates the hyperbolic sine of an angle


Parameters
angle - The angle to calculate hyperbolic sine for

Returns
The hyperbolic sine value

Examples
z = Math.sinh(someangle);

Notes
Make sure to include the Math. part as this method extends the built-in Math prototype


Math.cosh

Calculates the hyperbolic cosine of an angle


Parameters
angle - The angle to calculate hyperbolic cosine for

Returns
The hyperbolic cosine value

Examples
z = Math.cosh(someangle);

Notes
Make sure to include the Math. part as this method extends the built-in Math prototype


Math.nint

Converts a number to an integer, with optional rounding.


Parameters
value - The value to convert
round - If true, will round the result to the nearest integer, otherwise it will simply truncate. You can leave this parameter off, it will default to false.

Returns
The converted integer value

Examples
a = Math.nint(1.6, false);  // a will be 1
b = Math.nint(1.6, true); // b will be 2
c = Math.nint(1.6); // c will be 1

Notes
Make sure to include the Math. part as this method extends the built-in Math prototype


Math.sqrDist

Calculates the square of the distance between two points


Parameters
pt1 - An object with x and y properties.
pt2 - An object with x and y properties.

Returns
The square of the distance between pt1 and pt2. (To get the actual distance, you'll need to take the square root of this result)

Examples
var pt1 = {x:1, y:2};
var pt2 = {x:4, y:6};
var sd = Math.sqrDist(pt1, pt2);
// sd will be 25

Notes
The pt1 and pt2 parameters can be any object, as long as they have x and y properties that represent the point coordinates. Make sure to include the Math. part as this method extends the built-in Math prototype