Constructor
new LatLonNvectorSpherical(lat, lon)
Creates a LatLon point on spherical model earth.
Parameters:
Name | Type | Description |
---|---|---|
lat |
number | Latitude in degrees. |
lon |
number | Longitude in degrees. |
- Source:
Methods
(static) intersection(path1start, path1brngEnd, path2start, path2brngEnd) → {LatLon}
Returns the point of intersection of two paths each defined by point pairs or start point and bearing.
Parameters:
Name | Type | Description |
---|---|---|
path1start |
LatLon | Start point of first path. |
path1brngEnd |
LatLon | number | End point of first path or initial bearing from first start point. |
path2start |
LatLon | Start point of second path. |
path2brngEnd |
LatLon | number | End point of second path or initial bearing from second start point. |
- Source:
Returns:
Destination point (null if no unique intersection defined)
- Type
- LatLon
Example
var p1 = new LatLon(51.8853, 0.2545), brng1 = 108.55;
var p2 = new LatLon(49.0034, 2.5735), brng2 = 32.44;
var pInt = LatLon.intersection(p1, brng1, p2, brng2); // 50.9076°N, 004.5086°E
(static) meanOf(points) → {LatLon}
Returns point representing geographic mean of supplied points.
Parameters:
Name | Type | Description |
---|---|---|
points |
Array.<LatLon> | Array of points to be averaged. |
- Source:
Returns:
Point at the geographic mean of the supplied points.
- Type
- LatLon
bearingTo(point) → {number}
Returns the (initial) bearing from ‘this’ point to the specified point, in compass degrees.
Parameters:
Name | Type | Description |
---|---|---|
point |
LatLon | Latitude/longitude of destination point. |
- Source:
Returns:
Initial bearing in degrees from North (0°..360°).
- Type
- number
Example
var p1 = new LatLon(52.205, 0.119);
var p2 = new LatLon(48.857, 2.351);
var b1 = p1.bearingTo(p2); // 156.2°
crossTrackDistanceTo(pathStart, pathBrngEnd, radiusopt) → {number}
Returns (signed) distance from ‘this’ point to great circle defined by start-point and end-point/bearing.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pathStart |
LatLon | Start point of great circle path. | ||
pathBrngEnd |
LatLon | number | End point of great circle path or initial bearing from great circle start point. | ||
radius |
number |
<optional> |
6371e3 | (Mean) radius of earth (defaults to radius in metres). |
- Source:
Returns:
Distance to great circle (-ve if to left, +ve if to right of path).
- Type
- number
Example
var pCurrent = new LatLon(53.2611, -0.7972);
var p1 = new LatLon(53.3206, -1.7297), brng = 96.0;
var d = pCurrent.crossTrackDistanceTo(p1, brng); // Number(d.toPrecision(4)): -305.7
var p1 = new LatLon(53.3206, -1.7297), p2 = new LatLon(53.1887, 0.1334);
var d = pCurrent.crossTrackDistanceTo(p1, p2); // Number(d.toPrecision(4)): -307.5
destinationPoint(distance, bearing, radiusopt) → {LatLon}
Returns the destination point from ‘this’ point having travelled the given distance on the
given initial bearing (bearing will normally vary before destination is reached).
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
distance |
number | Distance travelled, in same units as earth radius (default: metres). | ||
bearing |
number | Initial bearing in degrees from north. | ||
radius |
number |
<optional> |
6371e3 | (Mean) radius of earth (defaults to radius in metres). |
- Source:
Returns:
Destination point.
- Type
- LatLon
Example
var p1 = new LatLon(51.4778, -0.0015);
var p2 = p1.destinationPoint(7794, 300.7); // 51.5135°N, 000.0983°W
distanceTo(point, radiusopt) → {number}
Returns the distance from ‘this’ point to the specified point.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
point |
LatLon | Latitude/longitude of destination point. | ||
radius |
number |
<optional> |
6371e3 | (Mean) radius of earth (defaults to radius in metres). |
- Source:
Returns:
Distance between this point and destination point, in same units as radius.
- Type
- number
Example
var p1 = new LatLon(52.205, 0.119), p2 = new LatLon(48.857, 2.351);
var d = p1.distanceTo(p2); // d.toPrecision(4): 404300
enclosedBy(points) → {bool}
Tests whether ‘this’ point is enclosed by the (convex) polygon defined by a set of points.
Parameters:
Name | Type | Description |
---|---|---|
points |
Array.<LatLon> | Ordered array of points defining vertices of polygon. |
- Source:
Throws:
-
If polygon is not convex.
- Type
- Error
Returns:
Whether this point is enclosed by region.
- Type
- bool
Example
var bounds = [ new LatLon(45,1), new LatLon(45,2), new LatLon(46,2), new LatLon(46,1) ];
var p = new LatLon(45,1, 1.1);
var inside = p.enclosedBy(bounds); // inside: true;
(private) equals(point) → {bool}
Checks if another point is equal to ‘this’ point.
Parameters:
Name | Type | Description |
---|---|---|
point |
LatLon | Point to be compared against this point. |
- Source:
Returns:
True if points are identical.
- Type
- bool
Example
var p1 = new LatLon(52.205, 0.119), p2 = new LatLon(52.205, 0.119);
var equal = p1.equals(p2); // equal: true
(private) greatCircle(bearing) → {Nvector}
Nvector normal to great circle obtained by heading on given bearing from ‘this’ point.
Direction of vector is such that initial bearing vector b = c × p.
Parameters:
Name | Type | Description |
---|---|---|
bearing |
number | Compass bearing in degrees. |
- Source:
Returns:
Normalised vector representing great circle.
- Type
- Nvector
Example
var p1 = new LatLon(53.3206, -1.7297);
var gc = p1.greatCircle(96.0); // [-0.794,0.129,0.594]
midpointTo(point) → {LatLon}
Returns the midpoint between ‘this’ point and specified point.
Parameters:
Name | Type | Description |
---|---|---|
point |
LatLon | Latitude/longitude of destination point. |
- Source:
Returns:
Midpoint between this point and destination point.
- Type
- LatLon
Example
var p1 = new LatLon(52.205, 0.119);
var p2 = new LatLon(48.857, 2.351);
var pMid = p1.midpointTo(p2); // 50.5363°N, 001.2746°E
nearestPointOnSegment(point1, point2) → {number}
Returns closest point on great circle segment between point1 & point2 to ‘this’ point.
If this point is ‘within’ the extent of the segment, the point is on the segment between point1 &
point2; otherwise, it is the closer of the endpoints defining the segment.
Parameters:
Name | Type | Description |
---|---|---|
point1 |
LatLon | Start point of great circle segment. |
point2 |
LatLon | End point of great circle segment. |
- Source:
Returns:
Nearest point on segment.
- Type
- number
Example
var p1 = new LatLon(51.0, 1.0), p2 = new LatLon(51.0, 2.0);
var p0 = new LatLon(51.0, 1.9);
var p = p0.nearestPointOnSegment(p1, p2); // 51.0004°N, 001.9000°E
var d = p.distanceTo(p); // 42.71
var p0 = new LatLon(51.0, 2.1);
var p = p0.nearestPointOnSegment(p1, p2); // 51.0000°N, 002.0000°E
(private) toNvector() → {Nvector}
Converts ‘this’ lat/lon point to n-vector (normal to earth's surface).
- Source:
Returns:
Normalised n-vector representing lat/lon point.
- Type
- Nvector
Example
var p = new LatLon(45, 45);
var v = p.toNvector(); // [0.5000,0.5000,0.7071]
toString(formatopt, dpopt) → {string}
Returns a string representation of ‘this’ point, formatted as degrees, degrees+minutes, or
degrees+minutes+seconds.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
format |
string |
<optional> |
dms | Format point as 'd', 'dm', 'dms'. |
dp |
number |
<optional> |
0|2|4 | Number of decimal places to use: default 0 for dms, 2 for dm, 4 for d. |
- Source:
Returns:
Comma-separated formatted latitude/longitude.
- Type
- string