OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
compute_dist.c
Go to the documentation of this file.
1 /*
2  * compute_dist.c
3  *
4  * Created on: Jun 29, 2016
5  * Author: rhealy
6  */
7 #include <math.h>
8 
9 
10 double deg2rad(double deg);
11 
12 /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
13 /*:: Compute the angular distance :*/
14 /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
15 
16 double angular_distance(double lat1, double lon1, double lat2, double lon2) {
17  double theta, dist;
18  theta = lon1 - lon2;
19  dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta));
20  dist = dist> 1? 1:dist;
21  dist = dist<-1?-1:dist;
22  return (acos(dist));
23 }
24 
25 /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
26 /*:: This function converts decimal degrees to radians :*/
27 /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
28 double deg2rad(double deg) {
29  return (deg * M_PI / 180);
30 }
31 /* and the inverse */
32 double rad2deg(double rad) {
33  return (rad * 180. / M_PI);
34 }
35 
double angular_distance(double lat1, double lon1, double lat2, double lon2)
Definition: compute_dist.c:16
double deg2rad(double deg)
Definition: compute_dist.c:28
#define M_PI
Definition: pml_iop.h:15
double rad2deg(double rad)
Definition: compute_dist.c:32