PostGIS  2.5.0dev-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 940 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().

941 {
942  double heading = 0.0;
943  double f;
944 
945  /* Starting from the poles? Special case. */
946  if ( FP_IS_ZERO(cos(s->lat)) )
947  return (s->lat > 0.0) ? M_PI : 0.0;
948 
949  f = (sin(e->lat) - sin(s->lat) * cos(d)) / (sin(d) * cos(s->lat));
950  if ( FP_EQUALS(f, 1.0) )
951  heading = 0.0;
952  else if ( FP_EQUALS(f, -1.0) )
953  heading = M_PI;
954  else if ( fabs(f) > 1.0 )
955  {
956  LWDEBUGF(4, "f = %g", f);
957  heading = acos(f);
958  }
959  else
960  heading = acos(f);
961 
962  if ( sin(e->lon - s->lon) < 0.0 )
963  heading = -1 * heading;
964 
965  return heading;
966 }
#define FP_IS_ZERO(A)
#define FP_EQUALS(A, B)
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88

Here is the caller graph for this function: