PostGIS  2.1.10dev-r@@SVN_REVISION@@
double sphere_direction ( const GEOGRAPHIC_POINT s,
const GEOGRAPHIC_POINT e,
double  d 
)

Given two points on a unit sphere, calculate the direction from s to e.

Definition at line 924 of file lwgeodetic.c.

References FP_EQUALS, FP_IS_ZERO, GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, and LWDEBUGF.

Referenced by circ_center_spherical(), test_sphere_direction(), and test_sphere_project().

925 {
926  double heading = 0.0;
927  double f;
928 
929  /* Starting from the poles? Special case. */
930  if ( FP_IS_ZERO(cos(s->lat)) )
931  return (s->lat > 0.0) ? M_PI : 0.0;
932 
933  f = (sin(e->lat) - sin(s->lat) * cos(d)) / (sin(d) * cos(s->lat));
934  if ( FP_EQUALS(f, 1.0) )
935  heading = 0.0;
936  else if ( fabs(f) > 1.0 )
937  {
938  LWDEBUGF(4, "f = %g", f);
939  heading = acos(f);
940  }
941  else
942  heading = acos(f);
943 
944  if ( sin(e->lon - s->lon) < 0.0 )
945  heading = -1 * heading;
946 
947  return heading;
948 }
#define FP_IS_ZERO(A)
#define FP_EQUALS(A, B)
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55

Here is the caller graph for this function: