PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ sphere_direction()

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 925 of file lwgeodetic.c.

References FP_EQUALS, FP_IS_ZERO, GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, LWDEBUGF, SIGNUM, sphere_direction(), and sphere_distance().

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

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