PostGIS  2.5.7dev-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 975 of file lwgeodetic.c.

976 {
977  double heading = 0.0;
978  double f;
979 
980  /* Starting from the poles? Special case. */
981  if ( FP_IS_ZERO(cos(s->lat)) )
982  return (s->lat > 0.0) ? M_PI : 0.0;
983 
984  f = (sin(e->lat) - sin(s->lat) * cos(d)) / (sin(d) * cos(s->lat));
985  if ( FP_EQUALS(f, 1.0) )
986  heading = 0.0;
987  else if ( FP_EQUALS(f, -1.0) )
988  heading = M_PI;
989  else if ( fabs(f) > 1.0 )
990  {
991  LWDEBUGF(4, "f = %g", f);
992  heading = acos(f);
993  }
994  else
995  heading = acos(f);
996 
997  if ( sin(e->lon - s->lon) < 0.0 )
998  heading = -1 * heading;
999 
1000  return heading;
1001 }
char * s
Definition: cu_in_wkt.c:23
#define FP_EQUALS(A, B)
#define FP_IS_ZERO(A)
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88

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

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

Here is the caller graph for this function: