Skip to content

File syn_geo.c

FileList > src > syntropic > util > syn_geo.c

Go to the source code of this file

Geodetic coordinate transformations and distance calculation implementation.

  • #include "../util/syn_assert.h"
  • #include "syn_geo.h"
  • #include <math.h>
  • #include <stddef.h>

Public Functions

Type Name
double syn_geo_3d_distance_m (const SYN_ENU * p1, const SYN_ENU * p2)
Compute 3D Euclidean Cartesian distance between two ENU points.
SYN_Status syn_geo_ecef_to_enu (double x, double y, double z, double ref_lat_deg, double ref_lon_deg, double ref_alt_m, SYN_ENU * out_enu)
Convert global ECEF coordinates to a Local East-North-Up (ENU) frame.
SYN_Status syn_geo_ecef_to_wgs84 (double x, double y, double z, double * out_lat, double * out_lon, double * out_alt)
Convert Earth-Centered Earth-Fixed (ECEF) coordinates back to WGS-84 Geodetic.
double syn_geo_haversine_m (double lat1_deg, double lon1_deg, double lat2_deg, double lon2_deg)
Compute 2D surface geodesic distance using the Haversine formula.
SYN_Status syn_geo_pos_from_gga (const SYN_NMEA_GGA * gga, SYN_GeoPos * out_pos)
Populate a SYN_GeoPos structure from a parsed NMEA GGA sentence.
SYN_Status syn_geo_wgs84_to_ecef (double lat_deg, double lon_deg, double alt_m, double * out_x, double * out_y, double * out_z)
Convert WGS-84 Geodetic coordinates to Earth-Centered Earth-Fixed (ECEF).
SYN_Status syn_geo_wgs84_to_enu (double lat_deg, double lon_deg, double alt_m, double ref_lat_deg, double ref_lon_deg, double ref_alt_m, SYN_ENU * out_enu)
Direct conversion from WGS-84 Geodetic to Local East-North-Up (ENU).

Macros

Type Name
define DEG_TO_RAD (M\_PI / 180.0)
define M_PI 3.14159265358979323846
define RAD_TO_DEG (180.0 / M\_PI)

Public Functions Documentation

function syn_geo_3d_distance_m

Compute 3D Euclidean Cartesian distance between two ENU points.

double syn_geo_3d_distance_m (
    const SYN_ENU * p1,
    const SYN_ENU * p2
) 

Parameters:

  • p1 Point 1 ENU coordinates in meters. Must not be NULL.
  • p2 Point 2 ENU coordinates in meters. Must not be NULL.

Returns:

3D Euclidean distance in meters.


function syn_geo_ecef_to_enu

Convert global ECEF coordinates to a Local East-North-Up (ENU) frame.

SYN_Status syn_geo_ecef_to_enu (
    double x,
    double y,
    double z,
    double ref_lat_deg,
    double ref_lon_deg,
    double ref_alt_m,
    SYN_ENU * out_enu
) 

Computes metric Cartesian offsets (East, North, Up) relative to a reference station origin (ref_lat_deg, ref_lon_deg, ref_alt_m).

Parameters:

  • x Target ECEF X in meters.
  • y Target ECEF Y in meters.
  • z Target ECEF Z in meters.
  • ref_lat_deg Reference origin Latitude in decimal degrees.
  • ref_lon_deg Reference origin Longitude in decimal degrees.
  • ref_alt_m Reference origin Altitude in meters.
  • out_enu Output ENU Cartesian coordinates. Must not be NULL.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if out_enu is NULL.


function syn_geo_ecef_to_wgs84

Convert Earth-Centered Earth-Fixed (ECEF) coordinates back to WGS-84 Geodetic.

SYN_Status syn_geo_ecef_to_wgs84 (
    double x,
    double y,
    double z,
    double * out_lat,
    double * out_lon,
    double * out_alt
) 

Uses Bowring's closed-form algorithm for high precision.

Parameters:

  • x ECEF X coordinate in meters.
  • y ECEF Y coordinate in meters.
  • z ECEF Z coordinate in meters.
  • out_lat Output Latitude in decimal degrees. Must not be NULL.
  • out_lon Output Longitude in decimal degrees. Must not be NULL.
  • out_alt Output Altitude in meters. Must not be NULL.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if outputs are NULL.


function syn_geo_haversine_m

Compute 2D surface geodesic distance using the Haversine formula.

double syn_geo_haversine_m (
    double lat1_deg,
    double lon1_deg,
    double lat2_deg,
    double lon2_deg
) 

Parameters:

  • lat1_deg Point 1 Latitude in decimal degrees.
  • lon1_deg Point 1 Longitude in decimal degrees.
  • lat2_deg Point 2 Latitude in decimal degrees.
  • lon2_deg Point 2 Longitude in decimal degrees.

Returns:

2D Surface distance in meters.


function syn_geo_pos_from_gga

Populate a SYN_GeoPos structure from a parsed NMEA GGA sentence.

SYN_Status syn_geo_pos_from_gga (
    const SYN_NMEA_GGA * gga,
    SYN_GeoPos * out_pos
) 

Assigns automatic accuracy estimate based on fix quality: * RTK_FIXED: 0.01 m (1 cm) * RTK_FLOAT: 0.20 m (20 cm) * DGPS: 1.00 m * GPS: 2.50 m * INVALID/EST: 50.0 m

Parameters:

  • gga Parsed NMEA GGA sentence. Must not be NULL.
  • out_pos Output SYN_GeoPos struct. Must not be NULL.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if args are NULL.


function syn_geo_wgs84_to_ecef

Convert WGS-84 Geodetic coordinates to Earth-Centered Earth-Fixed (ECEF).

SYN_Status syn_geo_wgs84_to_ecef (
    double lat_deg,
    double lon_deg,
    double alt_m,
    double * out_x,
    double * out_y,
    double * out_z
) 

Parameters:

  • lat_deg Latitude in decimal degrees (-90 to +90).
  • lon_deg Longitude in decimal degrees (-180 to +180).
  • alt_m Altitude above ellipsoid/MSL in meters.
  • out_x Output ECEF X coordinate in meters. Must not be NULL.
  • out_y Output ECEF Y coordinate in meters. Must not be NULL.
  • out_z Output ECEF Z coordinate in meters. Must not be NULL.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if outputs are NULL.


function syn_geo_wgs84_to_enu

Direct conversion from WGS-84 Geodetic to Local East-North-Up (ENU).

SYN_Status syn_geo_wgs84_to_enu (
    double lat_deg,
    double lon_deg,
    double alt_m,
    double ref_lat_deg,
    double ref_lon_deg,
    double ref_alt_m,
    SYN_ENU * out_enu
) 

Convenience function combining WGS84->ECEF and ECEF->ENU.

Parameters:

  • lat_deg Target Latitude in decimal degrees.
  • lon_deg Target Longitude in decimal degrees.
  • alt_m Target Altitude in meters.
  • ref_lat_deg Reference origin Latitude in decimal degrees.
  • ref_lon_deg Reference origin Longitude in decimal degrees.
  • ref_alt_m Reference origin Altitude in meters.
  • out_enu Output ENU Cartesian coordinates in meters.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if out_enu is NULL.


Macro Definition Documentation

define DEG_TO_RAD

#define DEG_TO_RAD `(M_PI / 180.0)`

define M_PI

#define M_PI `3.14159265358979323846`

define RAD_TO_DEG

#define RAD_TO_DEG `(180.0 / M_PI)`


The documentation for this class was generated from the following file src/syntropic/util/syn_geo.c