FACT++  1.0
int eraGc2gde ( double  a,
double  f,
double  xyz[3],
double *  elong,
double *  phi,
double *  height 
)

Definition at line 3 of file gc2gde.c.

References ERFA_DPI.

Referenced by eraGc2gd(), and t_gc2gde().

62 {
63  double aeps2, e2, e4t, ec2, ec, b, x, y, z, p2, absz, p, s0, pn, zc,
64  c0, c02, c03, s02, s03, a02, a0, a03, d0, f0, b0, s1,
65  cc, s12, cc2;
66 
67 
68 /* ------------- */
69 /* Preliminaries */
70 /* ------------- */
71 
72 /* Validate ellipsoid parameters. */
73  if ( f < 0.0 || f >= 1.0 ) return -1;
74  if ( a <= 0.0 ) return -2;
75 
76 /* Functions of ellipsoid parameters (with further validation of f). */
77  aeps2 = a*a * 1e-32;
78  e2 = (2.0 - f) * f;
79  e4t = e2*e2 * 1.5;
80  ec2 = 1.0 - e2;
81  if ( ec2 <= 0.0 ) return -1;
82  ec = sqrt(ec2);
83  b = a * ec;
84 
85 /* Cartesian components. */
86  x = xyz[0];
87  y = xyz[1];
88  z = xyz[2];
89 
90 /* Distance from polar axis squared. */
91  p2 = x*x + y*y;
92 
93 /* Longitude. */
94  *elong = p2 > 0.0 ? atan2(y, x) : 0.0;
95 
96 /* Unsigned z-coordinate. */
97  absz = fabs(z);
98 
99 /* Proceed unless polar case. */
100  if ( p2 > aeps2 ) {
101 
102  /* Distance from polar axis. */
103  p = sqrt(p2);
104 
105  /* Normalization. */
106  s0 = absz / a;
107  pn = p / a;
108  zc = ec * s0;
109 
110  /* Prepare Newton correction factors. */
111  c0 = ec * pn;
112  c02 = c0 * c0;
113  c03 = c02 * c0;
114  s02 = s0 * s0;
115  s03 = s02 * s0;
116  a02 = c02 + s02;
117  a0 = sqrt(a02);
118  a03 = a02 * a0;
119  d0 = zc*a03 + e2*s03;
120  f0 = pn*a03 - e2*c03;
121 
122  /* Prepare Halley correction factor. */
123  b0 = e4t * s02 * c02 * pn * (a0 - ec);
124  s1 = d0*f0 - b0*s0;
125  cc = ec * (f0*f0 - b0*c0);
126 
127  /* Evaluate latitude and height. */
128  *phi = atan(s1/cc);
129  s12 = s1 * s1;
130  cc2 = cc * cc;
131  *height = (p*cc + absz*s1 - a * sqrt(ec2*s12 + cc2)) /
132  sqrt(s12 + cc2);
133  } else {
134 
135  /* Exception: pole. */
136  *phi = ERFA_DPI / 2.0;
137  *height = absz - b;
138  }
139 
140 /* Restore sign of latitude. */
141  if ( z < 0 ) *phi = -*phi;
142 
143 /* OK status. */
144  return 0;
145 
146 }
#define ERFA_DPI
Definition: erfam.h:45
float height
Definition: HeadersGPS.h:26

+ Here is the caller graph for this function: