PostGIS  2.1.10dev-r@@SVN_REVISION@@
 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 1261 of file lwgeodetic.c.

Referenced by circ_center_spherical(), and test_sphere_project().

1262 {
1263  double d = distance;
1264  double lat1 = r->lat;
1265  double lon1 = r->lon;
1266  double lat2, lon2;
1267
1268  lat2 = asin(sin(lat1)*cos(d) + cos(lat1)*sin(d)*cos(azimuth));
1269
1270  /* If we're going straight up or straight down, we don't need to calculate the longitude */
1271  /* TODO: this isn't quite true, what if we're going over the pole? */
1272  if ( FP_EQUALS(azimuth, M_PI) || FP_EQUALS(azimuth, 0.0) )
1273  {
1274  lon2 = r->lon;
1275  }
1276  else
1277  {
1278  lon2 = lon1 + atan2(sin(azimuth)*sin(d)*cos(lat1), cos(d)-sin(lat1)*sin(lat2));
1279  }
1280
1281  if ( isnan(lat2) || isnan(lon2) )
1282  return LW_FAILURE;
1283
1284  n->lat = lat2;
1285  n->lon = lon2;
1286
1287  return LW_SUCCESS;
1288 }
#define LW_SUCCESS
Definition: liblwgeom.h:55
#define LW_FAILURE
Definition: liblwgeom.h:54
Datum distance(PG_FUNCTION_ARGS)
#define FP_EQUALS(A, B)

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