PostGIS  3.4.0dev-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 979 of file lwgeodetic.c.

980 {
981  double heading = 0.0;
982  double f;
983 
984  /* Starting from the poles? Special case. */
985  if ( FP_IS_ZERO(cos(s->lat)) )
986  return (s->lat > 0.0) ? M_PI : 0.0;
987 
988  f = (sin(e->lat) - sin(s->lat) * cos(d)) / (sin(d) * cos(s->lat));
989  if ( FP_EQUALS(f, 1.0) )
990  heading = 0.0;
991  else if ( FP_EQUALS(f, -1.0) )
992  heading = M_PI;
993  else if ( fabs(f) > 1.0 )
994  {
995  LWDEBUGF(4, "f = %g", f);
996  heading = acos(f);
997  }
998  else
999  heading = acos(f);
1000 
1001  if ( sin(e->lon - s->lon) < 0.0 )
1002  heading = -1 * heading;
1003 
1004  return heading;
1005 }
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(), interpolate_point4d_spheroid(), test_sphere_direction(), and test_sphere_project().

Here is the caller graph for this function: