PostGIS  2.4.9dev-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 971 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().

972 {
973  double heading = 0.0;
974  double f;
975 
976  /* Starting from the poles? Special case. */
977  if ( FP_IS_ZERO(cos(s->lat)) )
978  return (s->lat > 0.0) ? M_PI : 0.0;
979 
980  f = (sin(e->lat) - sin(s->lat) * cos(d)) / (sin(d) * cos(s->lat));
981  if ( FP_EQUALS(f, 1.0) )
982  heading = 0.0;
983  else if ( FP_EQUALS(f, -1.0) )
984  heading = M_PI;
985  else if ( fabs(f) > 1.0 )
986  {
987  LWDEBUGF(4, "f = %g", f);
988  heading = acos(f);
989  }
990  else
991  heading = acos(f);
992 
993  if ( sin(e->lon - s->lon) < 0.0 )
994  heading = -1 * heading;
995 
996  return heading;
997 }
#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: