Product: TIBCO Spotfire®
How to calculate the great circle distance between two points on Earth with the Haversine Formula.
The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes. This can be calculated in Spotfire with the use of custom expressions when given the latitude and longitude of two points on Earth.
Custom Expression of Haversine formula:
2 * 6371 * ASin(Sqrt((
Sin(([lat2 (radians)] - [lat1 (radians)]) / 2) * Sin(([lat2 (radians)] - [lat1 (radians)]) / 2)) + (Cos([lat1 (radians)]) * Cos([lat2 (radians)]) * Sin(([long2 (radians)] - [long1 (radians)]) / 2) * Sin(([long2 (radians)] - [long1 (radians)]) / 2))))
Required Input Columns:
- lat1 (radians) - latitutide of point 1
- long1 (radians) - longitude of point 1
- lat2 (radians) - latitutide of point 2
- long2 (radians) - longitude of point 2
See attached (Filename: Great Circle Distance between 2 points on earth with the Haversine Formula.dxp).
For TIBCO Spotfire versions 7.0 and higher:
The GreatCircleDistance() distance function was introduced in version 7.0 which greatly simplifies the calculation of the great circle distance between 2 points. See:
- d is the distance between the two points (along a great circle of the sphere; see spherical distance),
- r is the radius of the earth = 6367.46km (Note: not perfect sphere therefore cannot be guaranteed correct to better than 0.5%).
- : latitude of point 1 and latitude of point 2.
- : longitude of point 1 and longitude of point 2.
- Longtitude and Latitude are measured in in radians (note that ? and ? can be converted from degrees to radians by multiplying by ?/180 as usual).