protected internal override void Unproject(double x, double y, out double latitude, out double longitude) { double ros = x * x + (_ro_0 - y) * (_ro_0 - y); double a = _c_over_n2 - ros * _n_half; if (Double.IsNaN(a) || Math.Abs(a) > 1 + MathX.Tolerance) { throw new ArgumentOutOfRangeException("x, y"); } latitude = Math.Asin(MathX.Clamp(1, a)); longitude = MathX.Clamp(Math.PI, MathX.Atan2(x, _ro_0 - y, "x, y") * _inv_n); }
protected internal override void Project(double latitude, double longitude, out double x, out double y) { double sin_lat = Math.Sin(latitude); double cos_lat = Math.Cos(latitude); double sin_long = Math.Sin(longitude); double cos_long = Math.Cos(longitude); double a = _sin_fi_p * sin_lat - _cos_fi_p * cos_lat * sin_long; // sin_fi_p if (Double.IsNaN(a) || Math.Abs(a) > 1) { throw new ArgumentOutOfRangeException("latitude, longitude"); } x = MathX.Atan2(sin_lat / cos_lat * _cos_fi_p + sin_long * _sin_fi_p, cos_long, "latitude, longitude"); y = MathX.Clamp(MaxY, Math.Log((1 + a) / (1 - a)) / 2); // protect againt +-Infinity }
protected internal override void Unproject(double x, double y, out double latitude, out double longitude) { double sin_x = Math.Sin(x); double cos_x = Math.Cos(x); double sinh_y = Math.Sinh(y); double cosh_y = Math.Cosh(y); // cosh_y >= 1 by definition double a = (_sin_fi_p * sinh_y + _cos_fi_p * sin_x) / cosh_y; if (Math.Abs(a) > 1) { throw new ArgumentOutOfRangeException("x, y"); } latitude = Math.Asin(a); longitude = MathX.Atan2(_sin_fi_p * sin_x - _cos_fi_p * sinh_y, cos_x, "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 longtude will be 0 longitude = MathX.Atan2(Math.Sinh(x), Math.Cos(y)); } }