OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
geoCoord.hpp File Reference
+ Include dependency graph for geoCoord.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

EXTENSION_NOINLINE double _posAngleRads (double rads)
 
EXTENSION_INLINE double H3_EXPORT() degsToRads (double degrees)
 converts degrees to radians More...
 
EXTENSION_INLINE double H3_EXPORT() radsToDegs (double radians)
 converts radians to degrees More...
 
EXTENSION_INLINE double constrainLng (double lng)
 
EXTENSION_NOINLINE double _geoAzimuthRads (const GeoCoord(p1), const GeoCoord(p2))
 
EXTENSION_NOINLINE bool _geoAzDistanceRads (const GeoCoord(p1), double az, double distance, GeoCoord(p2))
 

Function Documentation

EXTENSION_NOINLINE bool _geoAzDistanceRads ( const   GeoCoordp1,
double  az,
double  distance,
GeoCoord(p2)   
)

Computes the point on the sphere a specified azimuth and distance from another point.

Parameters
p1The first spherical coordinates.
azThe desired azimuth from p1.
distanceThe desired distance from p1, must be non-negative.
p2The spherical coordinates at the desired azimuth and distance from p1.

Definition at line 204 of file geoCoord.hpp.

References _posAngleRads(), constrainLng(), EPSILON, GeoCoordCopy, LAT_INDEX, LON_INDEX, M_PI, and M_PI_2.

Referenced by _hex2dToGeo().

207  {
208  if (distance < EPSILON) {
209  GeoCoordCopy(p2, p1);
210  return true;
211  }
212 
213  double sinlat, sinlon, coslon;
214 
215  az = _posAngleRads(az);
216 
217  // check for due north/south azimuth
218  if (az < EPSILON || fabs(az - M_PI) < EPSILON) {
219  if (az < EPSILON) // due north
220  p2[LAT_INDEX] = p1[LAT_INDEX] + distance;
221  else // due south
222  p2[LAT_INDEX] = p1[LAT_INDEX] - distance;
223 
224  if (fabs(p2[LAT_INDEX] - M_PI_2) < EPSILON) // north pole
225  {
226  p2[LAT_INDEX] = M_PI_2;
227  p2[LON_INDEX] = 0.0;
228  } else if (fabs(p2[LAT_INDEX] + M_PI_2) < EPSILON) // south pole
229  {
230  p2[LAT_INDEX] = -M_PI_2;
231  p2[LON_INDEX] = 0.0;
232  } else
233  p2[LON_INDEX] = constrainLng(p1[LON_INDEX]);
234  } else // not due north or south
235  {
236  sinlat =
237  sin(p1[LAT_INDEX]) * cos(distance) + cos(p1[LAT_INDEX]) * sin(distance) * cos(az);
238  if (sinlat > 1.0)
239  sinlat = 1.0;
240  if (sinlat < -1.0)
241  sinlat = -1.0;
242  p2[LAT_INDEX] = asin(sinlat);
243  if (fabs(p2[LAT_INDEX] - M_PI_2) < EPSILON) // north pole
244  {
245  p2[LAT_INDEX] = M_PI_2;
246  p2[LON_INDEX] = 0.0;
247  } else if (fabs(p2[LAT_INDEX] + M_PI_2) < EPSILON) // south pole
248  {
249  p2[LAT_INDEX] = -M_PI_2;
250  p2[LON_INDEX] = 0.0;
251  } else {
252  sinlon = sin(az) * sin(distance) / cos(p2[LAT_INDEX]);
253  coslon = (cos(distance) - sin(p1[LAT_INDEX]) * sin(p2[LAT_INDEX])) /
254  cos(p1[LAT_INDEX]) / cos(p2[LAT_INDEX]);
255  if (sinlon > 1.0)
256  sinlon = 1.0;
257  if (sinlon < -1.0)
258  sinlon = -1.0;
259  if (coslon > 1.0)
260  coslon = 1.0;
261  if (coslon < -1.0)
262  coslon = -1.0;
263  p2[LON_INDEX] = constrainLng(p1[LON_INDEX] + atan2(sinlon, coslon));
264  }
265  }
266  return true;
267 }
EXTENSION_INLINE double constrainLng(double lng)
Definition: geoCoord.hpp:134
#define M_PI
Definition: constants.h:25
#define LAT_INDEX
Definition: h3api.h:92
EXTENSION_NOINLINE double _posAngleRads(double rads)
Definition: geoCoord.hpp:35
#define M_PI_2
Definition: constants.h:30
#define EPSILON
Definition: constants.h:42
#define LON_INDEX
Definition: h3api.h:93
#define GeoCoordCopy(dest_coord, src_coord)
Definition: h3api.h:96

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double _geoAzimuthRads ( const   GeoCoordp1,
const   GeoCoordp2 
)

The great circle distance in radians between two spherical coordinates.

This function uses the Haversine formula. For math details, see: https://en.wikipedia.org/wiki/Haversine_formula https://www.movable-type.co.uk/scripts/latlong.html

Parameters
athe first lat/lng pair (in radians)
bthe second lat/lng pair (in radians)
Returns
the great circle distance in radians between a and b The great circle distance in kilometers between two spherical coordinates. The great circle distance in meters between two spherical coordinates. Determines the azimuth to p2 from p1 in radians.
Parameters
p1The first spherical coordinates.
p2The second spherical coordinates.
Returns
The azimuth in radians from p1 to p2.

Definition at line 187 of file geoCoord.hpp.

References LAT_INDEX, and LON_INDEX.

Referenced by _geoToHex2d().

187  {
188  return atan2(
189  cos(p2[LAT_INDEX]) * sin(p2[LON_INDEX] - p1[LON_INDEX]),
190  cos(p1[LAT_INDEX]) * sin(p2[LAT_INDEX]) -
191  sin(p1[LAT_INDEX]) * cos(p2[LAT_INDEX]) * cos(p2[LON_INDEX] - p1[LON_INDEX]));
192 }
#define LAT_INDEX
Definition: h3api.h:92
#define LON_INDEX
Definition: h3api.h:93

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double _posAngleRads ( double  rads)

Normalizes radians to a value between 0.0 and two PI.

Parameters
radsThe input radians value.
Returns
The normalized radians value.

Definition at line 35 of file geoCoord.hpp.

References M_2PI.

Referenced by _geoAzDistanceRads(), _geoToHex2d(), and _hex2dToGeo().

35  {
36  double tmp = ((rads < 0.0) ? rads + M_2PI : rads);
37  if (rads >= M_2PI)
38  tmp -= M_2PI;
39  return tmp;
40 }
#define M_2PI
Definition: constants.h:34

+ Here is the caller graph for this function:

EXTENSION_INLINE double constrainLng ( double  lng)

constrainLat makes sure latitudes are in the proper bounds

Parameters
latThe original lat value
Returns
The corrected lat value constrainLng makes sure longitudes are in the proper bounds
Parameters
lngThe origin lng value
Returns
The corrected lng value

Definition at line 134 of file geoCoord.hpp.

References M_PI.

Referenced by _geoAzDistanceRads().

134  {
135  while (lng > M_PI) {
136  lng = lng - (2 * M_PI);
137  }
138  while (lng < -M_PI) {
139  lng = lng + (2 * M_PI);
140  }
141  return lng;
142 }
#define M_PI
Definition: constants.h:25

+ Here is the caller graph for this function: