1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 13:41:16 +01:00

Fixed broken equations

This commit is contained in:
Martin Tůma 2019-02-26 22:16:05 +01:00
parent 3ca5616a3c
commit a0697a6ce7
6 changed files with 25 additions and 25 deletions

View File

@ -20,10 +20,10 @@ RectC::RectC(const Coordinates &center, double radius)
double deltaLon = asin(sin(radDist) / cos(radlat)); double deltaLon = asin(sin(radDist) / cos(radlat));
minLon = radLon - deltaLon; minLon = radLon - deltaLon;
if (minLon < MIN_LON) if (minLon < MIN_LON)
minLon += M_2_PI; minLon += 2 * M_PI;
maxLon = radLon + deltaLon; maxLon = radLon + deltaLon;
if (maxLon > MAX_LON) if (maxLon > MAX_LON)
maxLon -= M_2_PI; maxLon -= 2 * M_PI;
} else { } else {
// a pole is within the distance // a pole is within the distance
minLat = qMax(minLat, MIN_LAT); minLat = qMax(minLat, MIN_LAT);

View File

@ -123,9 +123,9 @@ PointD AlbersEqual::ll2xy(const Coordinates &c) const
dlam = deg2rad(c.lon()) - _longitudeOrigin; dlam = deg2rad(c.lon()) - _longitudeOrigin;
if (dlam > M_PI) if (dlam > M_PI)
dlam -= M_2_PI; dlam -= 2 * M_PI;
if (dlam < -M_PI) if (dlam < -M_PI)
dlam += M_2_PI; dlam += 2 * M_PI;
sin_lat = sin(deg2rad(c.lat())); sin_lat = sin(deg2rad(c.lat()));
e_sin = _e * sin_lat; e_sin = _e * sin_lat;
@ -211,9 +211,9 @@ Coordinates AlbersEqual::xy2ll(const PointD &p) const
lon = _longitudeOrigin + theta / _n; lon = _longitudeOrigin + theta / _n;
if (lon > M_PI) if (lon > M_PI)
lon -= M_2_PI; lon -= 2 * M_PI;
if (lon < -M_PI) if (lon < -M_PI)
lon += M_2_PI; lon += 2 * M_PI;
if (lon > M_PI) if (lon > M_PI)
lon = M_PI; lon = M_PI;

View File

@ -57,7 +57,7 @@ Point3D Geocentric::fromGeodetic(const Coordinates &c, const Ellipsoid *e)
double Rn = e->radius() / (sqrt(1.0 - e->es() * slat2)); double Rn = e->radius() / (sqrt(1.0 - e->es() * slat2));
if (lon > M_PI) if (lon > M_PI)
lon -= M_2_PI; lon -= 2 * M_PI;
return Point3D(Rn * clat * cos(lon), Rn * clat * sin(lon), return Point3D(Rn * clat * cos(lon), Rn * clat * sin(lon),
(Rn * (1 - e->es())) * slat); (Rn * (1 - e->es())) * slat);

View File

@ -65,7 +65,7 @@ LambertConic1::LambertConic1(const Ellipsoid *ellipsoid, double latitudeOrigin,
lat_orig = deg2rad(latitudeOrigin); lat_orig = deg2rad(latitudeOrigin);
_longitudeOrigin = deg2rad(longitudeOrigin); _longitudeOrigin = deg2rad(longitudeOrigin);
if (_longitudeOrigin > M_PI) if (_longitudeOrigin > M_PI)
_longitudeOrigin -= M_2_PI; _longitudeOrigin -= 2 * M_PI;
_falseEasting = falseEasting; _falseEasting = falseEasting;
_falseNorthing = falseNorthing; _falseNorthing = falseNorthing;
@ -102,9 +102,9 @@ PointD LambertConic1::ll2xy(const Coordinates &c) const
dlam = deg2rad(c.lon()) - _longitudeOrigin; dlam = deg2rad(c.lon()) - _longitudeOrigin;
if (dlam > M_PI) if (dlam > M_PI)
dlam -= M_2_PI; dlam -= 2 * M_PI;
if (dlam < -M_PI) if (dlam < -M_PI)
dlam += M_2_PI; dlam += 2 * M_PI;
theta = _n * dlam; theta = _n * dlam;
@ -168,13 +168,13 @@ Coordinates LambertConic1::xy2ll(const PointD &p) const
if (lon - M_PI < 3.5e-6) if (lon - M_PI < 3.5e-6)
lon = M_PI; lon = M_PI;
else else
lon -= M_2_PI; lon -= 2 * M_PI;
} }
if (lon < -M_PI) { if (lon < -M_PI) {
if (fabs(lon + M_PI) < 3.5e-6) if (fabs(lon + M_PI) < 3.5e-6)
lon = -M_PI; lon = -M_PI;
else else
lon += M_2_PI; lon += 2 * M_PI;
} }
if (fabs(lon) < 2.0e-7) if (fabs(lon) < 2.0e-7)

View File

@ -56,7 +56,7 @@ Mercator::Mercator(const Ellipsoid *ellipsoid, double latitudeOrigin,
_latitudeOrigin = deg2rad(latitudeOrigin); _latitudeOrigin = deg2rad(latitudeOrigin);
_longitudeOrigin = deg2rad(longitudeOrigin); _longitudeOrigin = deg2rad(longitudeOrigin);
if (_longitudeOrigin > M_PI) if (_longitudeOrigin > M_PI)
_longitudeOrigin -= M_2_PI; _longitudeOrigin -= 2 * M_PI;
_falseNorthing = falseNorthing; _falseNorthing = falseNorthing;
_falseEasting = falseEasting; _falseEasting = falseEasting;
@ -86,16 +86,16 @@ PointD Mercator::ll2xy(const Coordinates &c) const
double pow_temp; double pow_temp;
if (lon > M_PI) if (lon > M_PI)
lon -= M_2_PI; lon -= 2 * M_PI;
e_x_sinlat = _e * sin(lat); e_x_sinlat = _e * sin(lat);
tan_temp = tan(M_PI_4 + lat / 2.e0); tan_temp = tan(M_PI_4 + lat / 2.e0);
pow_temp = pow((1.e0 - e_x_sinlat) / (1.e0 + e_x_sinlat), _e / 2.e0); pow_temp = pow((1.e0 - e_x_sinlat) / (1.e0 + e_x_sinlat), _e / 2.e0);
ctanz2 = tan_temp * pow_temp; ctanz2 = tan_temp * pow_temp;
delta_lon = lon - _longitudeOrigin; delta_lon = lon - _longitudeOrigin;
if (delta_lon > M_PI) if (delta_lon > M_PI)
delta_lon -= M_2_PI; delta_lon -= 2 * M_PI;
if (delta_lon < -M_PI) if (delta_lon < -M_PI)
delta_lon += M_2_PI; delta_lon += 2 * M_PI;
return PointD(_scaleFactor * _a * delta_lon + _falseEasting, return PointD(_scaleFactor * _a * delta_lon + _falseEasting,
_scaleFactor * _a * log(ctanz2) + _falseNorthing); _scaleFactor * _a * log(ctanz2) + _falseNorthing);
@ -115,9 +115,9 @@ Coordinates Mercator::xy2ll(const PointD &p) const
lat = xphi + _ab * sin(2.e0 * xphi) + _bb * sin(4.e0 * xphi) lat = xphi + _ab * sin(2.e0 * xphi) + _bb * sin(4.e0 * xphi)
+ _cb * sin(6.e0 * xphi) + _db * sin(8.e0 * xphi); + _cb * sin(6.e0 * xphi) + _db * sin(8.e0 * xphi);
if (lon > M_PI) if (lon > M_PI)
lon -= M_2_PI; lon -= 2 * M_PI;
if (lon < -M_PI) if (lon < -M_PI)
lon += M_2_PI; lon += 2 * M_PI;
return Coordinates(rad2deg(lon), rad2deg(lat)); return Coordinates(rad2deg(lon), rad2deg(lat));
} }

View File

@ -107,9 +107,9 @@ PointD TransverseMercator::ll2xy(const Coordinates &c) const
dlam = deg2rad(c.lon()) - _longitudeOrigin; dlam = deg2rad(c.lon()) - _longitudeOrigin;
if (dlam > M_PI) if (dlam > M_PI)
dlam -= M_2_PI; dlam -= 2 * M_PI;
if (dlam < -M_PI) if (dlam < -M_PI)
dlam += M_2_PI; dlam += 2 * M_PI;
if (fabs(dlam) < 2.e-10) if (fabs(dlam) < 2.e-10)
dlam = 0.0; dlam = 0.0;
@ -235,20 +235,20 @@ Coordinates TransverseMercator::xy2ll(const PointD &p) const
lat = M_PI - lat; lat = M_PI - lat;
lon += M_PI; lon += M_PI;
if (lon > M_PI) if (lon > M_PI)
lon -= M_2_PI; lon -= 2 * M_PI;
} }
while (lat < deg2rad(-90.0)) { while (lat < deg2rad(-90.0)) {
lat = - (lat + M_PI); lat = - (lat + M_PI);
lon += M_PI; lon += M_PI;
if (lon > M_PI) if (lon > M_PI)
lon -= M_2_PI; lon -= 2 * M_PI;
} }
if (lon > M_2_PI) if (lon > 2 * M_PI)
lon -= M_2_PI; lon -= 2 * M_PI;
if (lon < -M_PI) if (lon < -M_PI)
lon += M_2_PI; lon += 2 * M_PI;
return Coordinates(rad2deg(lon), rad2deg(lat)); return Coordinates(rad2deg(lon), rad2deg(lat));
} }