7 #include "../tools/MathToolbox.hpp" 10 #include "../tools/toolbox.hpp" 11 #include "../tools/errorhandler.hpp" 95 if ((new_latitude < -M_PI_2) || (new_latitude > M_PI_2))
97 printWarning(
"PositionWGS84::setLatitude: The given latitude (" +
99 " deg.) is outside the definition range for this value which is [-90,90]. " +
100 "Ignoring this error condition here - hopefully this value isn't used anywhere.");
108 if ((new_longitude < -M_PI) || (new_longitude > M_PI))
110 printWarning(
"PositionWGS84::setLongitude: The given longitude (" +
112 " deg.) is outside the definition range for this value which is [-180,180]. " +
113 "Ignoring this error condition here - hopefully this value isn't used anywhere.");
127 double m = Dm - 100.0 * D;
128 return (D + m / 60.0) *
deg2rad;
150 if ( H ==
'S' || H ==
's' )
179 if ( H ==
'W' || H ==
'w' )
197 std::stringstream out;
198 out <<
"[PositionWGS84(lat:" 256 printWarning(
"transformToTangentPlan(): At least one of the values latitude, longitude or altitude is NaN. Can't perform transformation! Returning NaN values!");
265 printWarning(
"transformToTangentPlan(): At least one of the origin's values latitude, longitude or altitude is NaN. Can't perform transformation! Returning NaN values!");
273 const double dWGS84_SemiMajorAxis = 6378137.0;
274 const double dWGS84_SemiMinorAxis = 6356752.3142;
275 const double dWGS84_Flatness = (dWGS84_SemiMajorAxis - dWGS84_SemiMinorAxis) / dWGS84_SemiMajorAxis;
276 const double dWGS84_Eccentricity2 = dWGS84_Flatness * (2.0 - dWGS84_Flatness);
283 const double dN = dWGS84_SemiMajorAxis / (sqrt(1.0 - (dWGS84_Eccentricity2 * sin(dLat) * sin(dLat))));
284 const double dX_ECEF = (dN + dHeight) * cos(dLat) * cos(dLong);
285 const double dY_ECEF = (dN + dHeight) * cos(dLat) * sin(dLong);
286 const double dZ_ECEF = ((dN * (1.0 - dWGS84_Eccentricity2)) + dHeight) * sin(dLat);
295 const double dN_0 = dWGS84_SemiMajorAxis / (sqrt(1.0 - (dWGS84_Eccentricity2 * sin(dOriginLat) * sin(dOriginLat))));
296 const double dX_0_ECEF = (dN_0 + dOriginHeight) * cos(dOriginLat) * cos(dOriginLong);
297 const double dY_0_ECEF = (dN_0 + dOriginHeight) * cos(dOriginLat) * sin(dOriginLong);
298 const double dZ_0_ECEF = ((dN_0 * (1.0 - (dWGS84_Eccentricity2))) + dOriginHeight) * sin(dOriginLat);
302 *easting = - sin(dOriginLong) * (dX_ECEF - dX_0_ECEF)
303 + cos(dOriginLong) * (dY_ECEF - dY_0_ECEF);
305 *northing = - sin(dOriginLat) * cos(dOriginLong) * (dX_ECEF - dX_0_ECEF)
306 - sin(dOriginLat) * sin(dOriginLong) * (dY_ECEF - dY_0_ECEF)
307 + cos(dOriginLat) * (dZ_ECEF - dZ_0_ECEF);
309 *height = cos(dOriginLat) * cos(dOriginLong) * (dX_ECEF - dX_0_ECEF)
310 + cos(dOriginLat) * sin(dOriginLong) * (dY_ECEF - dY_0_ECEF)
311 + sin(dOriginLat) * (dZ_ECEF - dZ_0_ECEF);
324 INT32 nNoIterationSteps;
333 double dPhi, dLambda;
339 const double dGps_SemiMajorAxis = 6378137.0;
340 const double dGps_SemiMinorAxis = 6356752.3142;
341 const double dGps_Flatness = (dGps_SemiMajorAxis - dGps_SemiMinorAxis) / dGps_SemiMajorAxis;
342 const double dGps_Eccentricity2 = dGps_Flatness * (2.0 - dGps_Flatness);
350 nNoIterationSteps = 200;
356 dN = dGps_SemiMajorAxis /
357 (sqrt(1 - (dGps_Eccentricity2 * sin(dOriginLat) * sin(dOriginLat))));
359 dX_0_ECEF = (dN + 0.0) * cos(dOriginLat) * cos(dOriginLong);
360 dY_0_ECEF = (dN + 0.0) * cos(dOriginLat) * sin(dOriginLong);
361 dZ_0_ECEF = ((dN * (1.0 - (dGps_Eccentricity2))) + 0.0) * sin(dOriginLat);
366 dLambda = dOriginLat;
369 dX_ECEF = -cos(dPhi) * sin(dLambda) * dX + sin(dPhi) * dY + cos(dPhi) * cos(dLambda) * 0.0 + dX_0_ECEF;
370 dY_ECEF = -sin(dPhi) * sin(dLambda) * dX - cos(dPhi) * dY + sin(dPhi) * cos(dLambda) * 0.0 + dY_0_ECEF;
371 dZ_ECEF = cos(dLambda) * dX + sin(dLambda) * 0.0 + dZ_0_ECEF;
374 dN = dGps_SemiMajorAxis;
375 dP = sqrt(dX_ECEF * dX_ECEF + dY_ECEF * dY_ECEF);
382 for (nCount = 0 ; nCount < nNoIterationSteps ; nCount++)
384 dLambda = atan((dZ_ECEF + dGps_Eccentricity2 * dN * sin(dLambda)) / dP);
385 dN = dGps_SemiMajorAxis / (sqrt(1.0 - (dGps_Eccentricity2 * sin(dLambda) * sin(dLambda))));
388 dLong = atan2(dY_ECEF, dX_ECEF);
419 return "GPS (Omnistar VBS)";
421 return "GPS (Omnistar HP)";
425 return "GPS (RTK float)";
427 return "GPS (RTK integer)";
431 return "Landmark positioning";
438 std::stringstream ret;
439 ret <<
"Unknown (" << type <<
")";
std::string toString(const PositionWGS84::PositionWGS84SourceType &type)
void setLongitudeInRad(double val)
Sets the longitude value of the WGS-84 position.
This class defines a point in the three-dimensional plane.
bool operator==(const PositionWGS84 &other) const
Equality predicate.
Point3D getCartesianRelPos(const PositionWGS84 &orign) const
double getLongitudeInRad() const
Returns the longitude value of the WGS-84 position.
PositionWGS84()
Constructor.
double getLatitudeInRad() const
Returns the latitude value of the WGS-84 position.
double dist(const PositionWGS84 &pos) const
Calculates the distance in [m] from this to position in argument.
void setLatitudeInNMEA(double Dm, char H)
Sets the latitude value of the WGS-84 position.
void transformToTangentialPlane(const PositionWGS84 &origin, double *easting, double *northing, double *height) const
std::string getSourceString() const
Returns a std::string with a describtion of the WGS-84 position source.
time_t m_timeOfMeasurement
double NMEA2rad(double Dm)
Calculates the WGS84 coordinate in rad from the mixed degree-minute value usually found on NMEA compa...
double distanceToPos(const PositionWGS84 &pos) const
double getAltitudeInMeterMSL() const
Returns the altitude in meter above mean sea level.
double m_altitudeMSLSigma
void transformFromTangentialPlane(double dX, double dY, const PositionWGS84 &origin)
PositionWGS84SourceType m_source
void setLatitudeInRad(double val)
Sets the latitude value of the WGS-84 position.
void resetToDefault()
Resets all values of the position to their default values.
void setLongitudeInNMEA(double Dm, char H)
Sets the longitude value of the WGS-84 position.
double m_courseAngleSigma
void printWarning(std::string message)
std::string toString() const
Returns a std::string with a describtion of the WGS-84 position.