GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
rhumbline.c
Go to the documentation of this file.
1 
30 #include <math.h>
31 #include <grass/gis.h>
32 #include "pi.h"
33 
34 
35 static int adjust_lat(double *);
36 
37 #if 0
38 static int adjust_lon(double *);
39 #endif /* unused */
40 
41 static double TAN_A, TAN1, TAN2, L;
42 static int parallel;
43 
44 
57 int G_begin_rhumbline_equation(double lon1, double lat1, double lon2,
58  double lat2)
59 {
60  adjust_lat(&lat1);
61  adjust_lat(&lat2);
62 
63  if (lon1 == lon2) {
64  parallel = 1; /* a lie */
65  L = lat1;
66  return 0;
67  }
68  if (lat1 == lat2) {
69  parallel = 1;
70  L = lat1;
71  return 1;
72  }
73  parallel = 0;
74  lon1 = Radians(lon1);
75  lon2 = Radians(lon2);
76  lat1 = Radians(lat1);
77  lat2 = Radians(lat2);
78 
79  TAN1 = tan(M_PI_4 + lat1 / 2.0);
80  TAN2 = tan(M_PI_4 + lat2 / 2.0);
81  TAN_A = (lon2 - lon1) / (log(TAN2) - log(TAN1));
82  L = lon1;
83 
84  return 1;
85 }
86 
87 
97 double G_rhumbline_lat_from_lon(double lon)
98 {
99  if (parallel)
100  return L;
101 
102  lon = Radians(lon);
103 
104  return Degrees(2 * atan(exp((lon - L) / TAN_A) * TAN1) - M_PI_2);
105 }
106 
107 
108 #if 0
109 static int adjust_lon(double *lon)
110 {
111  while (*lon > 180.0)
112  *lon -= 360.0;
113  while (*lon < -180.0)
114  *lon += 360.0;
115 
116  return 0;
117 }
118 #endif /* unused */
119 
120 
121 static int adjust_lat(double *lat)
122 {
123  if (*lat > 90.0)
124  *lat = 90.0;
125  if (*lat < -90.0)
126  *lat = -90.0;
127 
128  return 0;
129 }
log
Definition: wxnviz.py:54
int G_begin_rhumbline_equation(double lon1, double lat1, double lon2, double lat2)
Start rhumbline calculations.
Definition: rhumbline.c:57
double G_rhumbline_lat_from_lon(double lon)
Calculates rhumbline latitude.
Definition: rhumbline.c:97
#define Radians(x)
Definition: pi.h:6
#define Degrees(x)
Definition: pi.h:7