PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ sphere_project()

int sphere_project ( const GEOGRAPHIC_POINT r,
double  distance,
double  azimuth,
GEOGRAPHIC_POINT n 
)

Given a starting location r, a distance and an azimuth to the new point, compute the location of the projected point on the unit sphere.

Definition at line 1314 of file lwgeodetic.c.

1315 {
1316  double d = distance;
1317  double lat1 = r->lat;
1318  double lon1 = r->lon;
1319  double lat2, lon2;
1320 
1321  lat2 = asin(sin(lat1)*cos(d) + cos(lat1)*sin(d)*cos(azimuth));
1322 
1323  /* If we're going straight up or straight down, we don't need to calculate the longitude */
1324  /* TODO: this isn't quite true, what if we're going over the pole? */
1325  if ( FP_EQUALS(azimuth, M_PI) || FP_EQUALS(azimuth, 0.0) )
1326  {
1327  lon2 = r->lon;
1328  }
1329  else
1330  {
1331  lon2 = lon1 + atan2(sin(azimuth)*sin(d)*cos(lat1), cos(d)-sin(lat1)*sin(lat2));
1332  }
1333 
1334  if ( isnan(lat2) || isnan(lon2) )
1335  return LW_FAILURE;
1336 
1337  n->lat = lat2;
1338  n->lon = lon2;
1339 
1340  return LW_SUCCESS;
1341 }
char * r
Definition: cu_in_wkt.c:24
#define LW_FAILURE
Definition: liblwgeom.h:79
#define LW_SUCCESS
Definition: liblwgeom.h:80
#define FP_EQUALS(A, B)
Datum distance(PG_FUNCTION_ARGS)

References distance(), FP_EQUALS, GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, LW_FAILURE, LW_SUCCESS, and r.

Referenced by circ_center_spherical(), and test_sphere_project().

Here is the call graph for this function:
Here is the caller graph for this function: