PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ sphere_distance()

double sphere_distance ( const GEOGRAPHIC_POINT s,
const GEOGRAPHIC_POINT e 
)

Given two points on a unit sphere, calculate their distance apart in radians.

Definition at line 948 of file lwgeodetic.c.

949 {
950  double d_lon, cos_d_lon, cos_lat_e, sin_lat_e, cos_lat_s, sin_lat_s;
951  double a1, a2, a, b;
952 
953  if (FP_EQUALS(s->lat, e->lat) && FP_EQUALS(s->lon, e->lon)) return 0.0;
954  d_lon = e->lon - s->lon;
955  cos_d_lon = cos(d_lon);
956  cos_lat_e = cos(e->lat);
957  sin_lat_e = sin(e->lat);
958  cos_lat_s = cos(s->lat);
959  sin_lat_s = sin(s->lat);
960 
961  a1 = POW2(cos_lat_e * sin(d_lon));
962  a2 = POW2(cos_lat_s * sin_lat_e - sin_lat_s * cos_lat_e * cos_d_lon);
963  a = sqrt(a1 + a2);
964  b = sin_lat_s * sin_lat_e + cos_lat_s * cos_lat_e * cos_d_lon;
965  return atan2(a, b);
966 }
char * s
Definition: cu_in_wkt.c:23
#define FP_EQUALS(A, B)
#define POW2(x)
Definition: lwgeodetic.h:48

References FP_EQUALS, GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, POW2, and s.

Referenced by circ_internal_nodes_sort(), circ_node_internal_new(), circ_node_leaf_new(), circ_node_max_distance(), circ_node_min_distance(), circ_tree_distance_tree(), circ_tree_distance_tree_internal(), edge_calculate_gbox_slow(), edge_distance_to_point(), geography_interpolate_points(), geography_substring(), interpolate_point4d_spheroid(), ptarray_distance_spheroid(), ptarray_length_spheroid(), ptarray_locate_point_spheroid(), ptarray_segmentize_sphere(), test_sphere_direction(), and test_sphere_project().

Here is the caller graph for this function: