Last active
February 12, 2018 18:49
-
-
Save dharanad/56e06e97c3d7e85082d61c757f0986b0 to your computer and use it in GitHub Desktop.
Great Circle Distance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
#include <stdio.h> | |
/** | |
* @brief haversineDistance finds the | |
* [great-circle distance](https://en.wikipedia.org/wiki/Great-circle_distance) | |
* between two points on a sphere. | |
* @see https://en.wikipedia.org/wiki/Haversine_formula. | |
* | |
* Parameters are the latitude and longitude of the first and second point in | |
* radians, respectively. | |
* | |
* @return the great-circle distance in kilometers. | |
*/ | |
double haversineDistance(double th1, double ph1, double th2, double ph2) { | |
double dx, dy, dz; | |
ph1 -= ph2; | |
dz = sin(th1) - sin(th2); | |
dx = cos(ph1) * cos(th1) - cos(th2); | |
dy = sin(ph1) * cos(th1); | |
return asin(sqrt(dx * dx + dy * dy + dz * dz) / 2) * 2 * R; | |
} | |
double to_radians(double degree) { | |
return (degree * M_PI) / 180.0; | |
} | |
int main(int argc, char **argc){ | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great Circle Distance formula, it is used to find distance between two point in a sphere.