-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgccalc.c
71 lines (60 loc) · 2.17 KB
/
gccalc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*********************************************************************/
/* */
/* This Program Written By Paul Edwards. */
/* Released to the public domain. */
/* */
/*********************************************************************/
/*********************************************************************/
/* */
/* gccalc - great circle calculations */
/* */
/* degdist - calculate distance for degrees (DDD.DDDD) to metres. */
/* raddist - calculate distance for radians to radians. */
/* d2r - convert degrees to radians. */
/* r2m - convert radians to metres. */
/* */
/*********************************************************************/
#include <math.h>
#include "gccalc.h"
#define pi 3.14159
double d2r(double deg)
{
double r;
r = (2 * pi) * (deg / 360.0);
return (r);
}
double r2m(double rad)
{
double m;
m = rad * 180 * 60 / pi * 1852.0;
return (m);
}
double degdist(double lat1, double lon1, double lat2, double lon2)
{
double d;
d = raddist(d2r(lat1), d2r(lon1), d2r(lat2), d2r(lon2));
d = r2m(d);
return (d);
}
double raddist(double lat1, double lon1, double lat2, double lon2)
{
double d;
d = 2
* asin(
sqrt(
pow(
sin(
((lat1-lat2)/2)
), 2
)
+ cos(lat1)
* cos(lat2)
* pow(
sin(
((lon1-lon2)/2)
), 2
)
)
);
return (d);
}