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

1321 {
1322  double d = distance;
1323  double lat1 = r->lat;
1324  double lon1 = r->lon;
1325  double lat2, lon2;
1326 
1327  lat2 = asin(sin(lat1)*cos(d) + cos(lat1)*sin(d)*cos(azimuth));
1328 
1329  /* If we're going straight up or straight down, we don't need to calculate the longitude */
1330  /* TODO: this isn't quite true, what if we're going over the pole? */
1331  if ( FP_EQUALS(azimuth, M_PI) || FP_EQUALS(azimuth, 0.0) )
1332  {
1333  lon2 = r->lon;
1334  }
1335  else
1336  {
1337  lon2 = lon1 + atan2(sin(azimuth)*sin(d)*cos(lat1), cos(d)-sin(lat1)*sin(lat2));
1338  }
1339 
1340  if ( isnan(lat2) || isnan(lon2) )
1341  return LW_FAILURE;
1342 
1343  n->lat = lat2;
1344  n->lon = lon2;
1345 
1346  return LW_SUCCESS;
1347 }
char * r
Definition: cu_in_wkt.c:24
#define LW_FAILURE
Definition: liblwgeom.h:96
#define LW_SUCCESS
Definition: liblwgeom.h:97
#define FP_EQUALS(A, B)
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032

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

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

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