PostGIS  3.3.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 927 of file lwgeodetic.c.

928 {
929  double heading = 0.0;
930  double f;
931 
932  /* Starting from the poles? Special case. */
933  if ( FP_IS_ZERO(cos(s->lat)) )
934  return (s->lat > 0.0) ? M_PI : 0.0;
935 
936  f = (sin(e->lat) - sin(s->lat) * cos(d)) / (sin(d) * cos(s->lat));
937  if ( FP_EQUALS(f, 1.0) )
938  heading = 0.0;
939  else if ( FP_EQUALS(f, -1.0) )
940  heading = M_PI;
941  else if ( fabs(f) > 1.0 )
942  {
943  LWDEBUGF(4, "f = %g", f);
944  heading = acos(f);
945  }
946  else
947  heading = acos(f);
948 
949  if ( sin(e->lon - s->lon) < 0.0 )
950  heading = -1 * heading;
951 
952  return heading;
953 }
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: