protected internal override void Unproject(double x, double y, out double latitude, out double longitude) { var ros = x * x + (_ro0 - y) * (_ro0 - y); var a = _cOverN2 - ros * _nHalf; if (double.IsNaN(a) || Math.Abs(a) > 1 + MathX.Tolerance) { throw new ArgumentOutOfRangeException(paramName: string.Join(",", new [] { nameof(x), nameof(y) })); } latitude = Math.Asin(MathX.Clamp(1, a)); longitude = MathX.Clamp(Math.PI, MathX.Atan2(x, _ro0 - y, "x, y") * _invN); }
protected internal override void Project(double latitude, double longitude, out double x, out double y) { var sinLatitude = Math.Sin(latitude); var cosLatitude = Math.Cos(latitude); var sinLongitude = Math.Sin(longitude); var cosLongitude = Math.Cos(longitude); var a = _sinFiP * sinLatitude - _cosFiP * cosLatitude * sinLongitude; // sin_fi_p if (double.IsNaN(a) || Math.Abs(a) > 1) { throw new ArgumentOutOfRangeException(string.Join(",", new[] { nameof(latitude), nameof(longitude) })); } x = MathX.Atan2(sinLatitude / cosLatitude * _cosFiP + sinLongitude * _sinFiP, cosLongitude, "latitude, longitude"); y = MathX.Clamp(MaxY, Math.Log((1 + a) / (1 - a)) / 2); // protect against +-Infinity }
protected internal override void Unproject(double x, double y, out double latitude, out double longitude) { var sinX = Math.Sin(x); var cosX = Math.Cos(x); var sinhY = Math.Sinh(y); var coshY = Math.Cosh(y); // cosh_y >= 1 by definition var a = (_sinFiP * sinhY + _cosFiP * sinX) / coshY; if (Math.Abs(a) > 1) { throw new ArgumentOutOfRangeException(string.Join(",", new [] { nameof(x), nameof(y) })); } latitude = Math.Asin(a); longitude = MathX.Atan2(_sinFiP * sinX - _cosFiP * sinhY, cosX, "x, y"); }
protected internal override void Unproject(double x, double y, out double latitude, out double longitude) { if (x >= MaxX) { latitude = 0; longitude = Math.PI / 2; } else if (x <= -MaxX) { latitude = 0; longitude = -Math.PI / 2; } else { // 1 <= cosh(x) <= cosh(MaxX) latitude = Math.Asin(Math.Sin(y) / Math.Cosh(x)); // In case of x=0 and y=+-Pi/2: latitude will be +-90 and longitude will be 0 longitude = MathX.Atan2(Math.Sinh(x), Math.Cos(y)); } }