Skip to content

Commit

Permalink
added ENU coordinates handling to geographic positions
Browse files Browse the repository at this point in the history
  • Loading branch information
mirad committed Apr 20, 2018
1 parent 9624c80 commit 4838443
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
54 changes: 52 additions & 2 deletions src/mobility/model/geographic-positions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,65 @@ GeographicPositions::GeographicToCartesianCoordinates (double latitude,
e = EARTH_WGS84_ECCENTRICITY;
}

double Rn = a / (sqrt (1 - pow (e, 2) * pow (sin (latitudeRadians), 2))); // radius of
// curvature
double Rn = a / (sqrt (1 - pow (e, 2) * pow (sin (latitudeRadians), 2))); // radius of curvature
double x = (Rn + altitude) * cos (latitudeRadians) * cos (longitudeRadians);
double y = (Rn + altitude) * cos (latitudeRadians) * sin (longitudeRadians);
double z = ((1 - pow (e, 2)) * Rn + altitude) * sin (latitudeRadians);
Vector cartesianCoordinates = Vector (x, y, z);
return cartesianCoordinates;
}

Vector
GeographicPositions::CartesianCoordinatesToEnu (double x,
double y,
double z,
double latitude0,
double longitude0,
double altitude0,
EarthSpheroidType sphType0)
{
NS_LOG_FUNCTION_NOARGS ();
double latitudeRadians0 = 0.01745329 * latitude0; // lambda
double longitudeRadians0 = 0.01745329 * longitude0; // phi
// Get the cartesianCoordinates (ECEF) from the local Geodetic point
Vector cartesianCoordinates0 = GeographicToCartesianCoordinates(latitude0, longitude0, altitude0, sphType0);

// Conduct some difference calculuation for better readability of the matrix operation below
double xd, yd, zd;
xd = x - cartesianCoordinates0.x;
yd = y - cartesianCoordinates0.y;
zd = z - cartesianCoordinates0.z;

double sin_phi = sin(longitudeRadians0);
double cos_phi = cos(longitudeRadians0);
double sin_lambda = sin(latitudeRadians0);
double cos_lambda = cos(latitudeRadians0);
// Codunct the transformation using a matrix multiplication.
double xEast = -sin_phi * xd + cos_phi * yd;
double yNorth = -cos_phi * sin_lambda * xd - sin_lambda * sin_phi * yd + cos_lambda * zd;
double yUp = cos_lambda * cos_phi * xd + cos_lambda * sin_phi * yd + sin_lambda * zd;

Vector enuCoordinates = Vector(xEast, yNorth, yUp);
return enuCoordinates;
}


Vector
GeographicPositions::GeographicToEnu (double latitude,
double longitude,
double altitude,
double latitude0,
double longitude0,
double altitude0,
EarthSpheroidType sphType)
{
// First to Cartesian, afterwards to ENU
Vector cartCoord = GeographicToCartesianCoordinates(latitude, longitude, altitude, sphType);
Vector enuCoordinates = CartesianCoordinatesToEnu(cartCoord.x,cartCoord.y, cartCoord.z, latitude0, longitude0, altitude0, sphType);

return enuCoordinates;
}

std::list<Vector>
GeographicPositions::RandCartesianPointsAroundGeographicPoint (double originLatitude,
double originLongitude,
Expand Down
53 changes: 53 additions & 0 deletions src/mobility/model/geographic-positions.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,59 @@ class GeographicPositions
double longitude,
double altitude,
EarthSpheroidType sphType);

/** Converts the Earth-Centered Earth-Fixed (ECEF) coordinates
* or called Cartesian coordinates in ns3 (x, y, z)
* to East-North-Up coordinates in a Local Tangent Plane that is centered at the
* Geodetic point (latitude0, longitude0, altitude0)
* Source: https://gist.github.com/govert/1b373696c9a27ff4c72a
*
* @param Cartesian coordinate x of the regared point
* @param Cartesian coordinate y of the regared point
* @param Cartesian coordinate z of the regared point
* @param reference latitude0 (in degrees) of the center-point
* @param reference longitude0 (in degrees) of the center-point
* @param reference altitude0 (meter) of the center-point above earth's surface
* @param sphType earth spheroid model to use for conversion
*
* @return a Vector containing the ENU coordinates (x, y, z referenced in meters)
* of the regared point, centered at the center-point
*
*/
static Vector CartesianCoordinatesToEnu (double x,
double y,
double z,
double latitude0,
double longitude0,
double altitude0,
EarthSpheroidType sphType0);


/** Converts earth geographic/geodetic coordinates (latitude and longitude in
* degrees) with a given altitude above earth's surface (in meters) to
* East-North-Up coordinates in a local tangent plane that is centered at the
* Geodetic point (latitude0, longitude0, altitude0)
* Source: https://gist.github.com/govert/1b373696c9a27ff4c72a
*
* @param latitude (in degrees)
* @param longitude (in degrees)
* @param Cartesian coordinate z
* @param reference latitude0 (in degrees) of the center-point
* @param reference longitude0 (in degrees) of the center-point
* @param reference altitude0 (meter) of the center-point, above earth's surface
* @param sphType earth spheroid model to use for conversion
*
*
* @return a Vector containing the ENU coordinates (x, y, z referenced in meters)
* of the regared point, centered at the center-point
*/
static Vector GeographicToEnu (double latitude,
double longitude,
double altitude,
double latitude0,
double longitude0,
double altitude0,
EarthSpheroidType sphType0);

/**
* Generates uniformly distributed random points (in ECEF Cartesian
Expand Down
1 change: 1 addition & 0 deletions src/mobility/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def build(bld):
'test/steady-state-random-waypoint-mobility-model-test.cc',
'test/waypoint-mobility-model-test.cc',
'test/geo-to-cartesian-test.cc',
'test/cartesian-to-enu-test.cc',
'test/rand-cart-around-geo-test.cc',
]

Expand Down

0 comments on commit 4838443

Please sign in to comment.