PostGIS  2.5.1dev-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 944 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().

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