PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ distance_ellipse_calculation()

double distance_ellipse_calculation ( double  lat1,
double  long1,
double  lat2,
double  long2,
SPHEROID sphere 
)

Definition at line 245 of file lwgeom_spheroid.c.

247 {
248  /*
249  * Code is taken from David Skea
250  * Geographic Data BC, Province of British Columbia, Canada.
251  * Thanks to GDBC and David Skea for allowing this to be
252  * put in PostGIS.
253  */
254 
255  double L1,L2,sinU1,sinU2,cosU1,cosU2;
256  double dl,dl1,dl2,dl3,cosdl1,sindl1;
257  double cosSigma,sigma,azimuthEQ,tsm;
258  double u2,A,B;
259  double dsigma;
260 
261  double TEMP;
262 
263  int iterations;
264 
265 
266  L1 = atan((1.0 - sphere->f ) * tan( lat1) );
267  L2 = atan((1.0 - sphere->f ) * tan( lat2) );
268  sinU1 = sin(L1);
269  sinU2 = sin(L2);
270  cosU1 = cos(L1);
271  cosU2 = cos(L2);
272 
273  dl = long2- long1;
274  dl1 = dl;
275  cosdl1 = cos(dl);
276  sindl1 = sin(dl);
277  iterations = 0;
278  do
279  {
280  cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosdl1;
281  sigma = acos(cosSigma);
282  azimuthEQ = asin((cosU1 * cosU2 * sindl1)/sin(sigma));
283 
284  /*
285  * Patch from Patrica Tozer to handle minor
286  * mathematical stability problem
287  */
288  TEMP = cosSigma - (2.0 * sinU1 * sinU2)/
289  (cos(azimuthEQ)*cos(azimuthEQ));
290  if (TEMP > 1)
291  {
292  TEMP = 1;
293  }
294  else if (TEMP < -1)
295  {
296  TEMP = -1;
297  }
298  tsm = acos(TEMP);
299 
300 
301  /* (old code?)
302  tsm = acos(cosSigma - (2.0 * sinU1 * sinU2)/(cos(azimuthEQ)*cos(azimuthEQ)));
303  */
304 
305  dl2 = deltaLongitude(azimuthEQ, sigma, tsm,sphere);
306  dl3 = dl1 - (dl + dl2);
307  dl1 = dl + dl2;
308  cosdl1 = cos(dl1);
309  sindl1 = sin(dl1);
310  iterations++;
311  }
312  while ( (iterations<999) && (fabs(dl3) > 1.0e-032));
313 
314  /* compute expansions A and B */
315  u2 = mu2(azimuthEQ,sphere);
316  A = bigA(u2);
317  B = bigB(u2);
318 
319  /* compute length of geodesic */
320  dsigma = B * sin(sigma) * (cos(tsm) +
321  (B*cosSigma*(-1.0 + 2.0 * (cos(tsm)*cos(tsm))))/4.0);
322  return sphere->b * (A * (sigma - dsigma));
323 }
double bigB(double u2)
double mu2(double azimuth, SPHEROID *sphere)
double bigA(double u2)
double deltaLongitude(double azimuth, double sigma, double tsm, SPHEROID *sphere)
double b
Definition: liblwgeom.h:362
double f
Definition: liblwgeom.h:363

References SPHEROID::b, bigA(), bigB(), deltaLongitude(), SPHEROID::f, and mu2().

Referenced by distance_ellipse().

Here is the call graph for this function:
Here is the caller graph for this function: