public override Coordinate ProjectInverse(double x, double y, Coordinate coord) { x /= ScaleFactor; y /= ScaleFactor; double rho = ProjectionMath.Distance(x, y = rho0 - y); if (rho != 0) { if (n < 0.0) { rho = -rho; x = -x; y = -y; } if (Spherical) { coord.Y = 2.0 * Math.Atan(Math.Pow(c / rho, 1.0 / n)) - ProjectionMath.PiHalf; } else { coord.Y = ProjectionMath.Phi2(Math.Pow(rho / c, 1.0 / n), Eccentricity); } coord.X = Math.Atan2(x, y) / n; } else { coord.X = 0.0; coord.Y = n > 0.0 ? ProjectionMath.PiHalf : -ProjectionMath.PiHalf; } return(coord); }
public override Coordinate ProjectInverse(double xyx, double xyy, Coordinate lp) { double rho; rho = ProjectionMath.Distance(xyx, lp.Y = _rho0 - xyy); if (_n < 0.0) { rho = -rho; lp.X = -xyx; lp.Y = -xyy; } lp.X = Math.Atan2(xyx, xyy) / _n; switch (ConicType) { case ConicTypes.PerspectiveConic: lp.Y = Math.Atan(_c1 - rho / _c2) + _sig; break; case ConicTypes.Murdoch2: lp.Y = _sig - Math.Atan(rho - _rhoC); break; default: lp.Y = _rhoC - rho; break; } return(lp); }
public override Coordinate ProjectInverse(double xyx, double xyy, Coordinate coord) { double t, r, rp, rl, al, z = 0, fAz, Az, s, c, Av; Boolean neg; int i; if (noskew) { t = xyx; coord.X = -xyx * cAzc + xyy * sAzc; coord.Y = -xyy * cAzc - t * sAzc; } if (neg = (xyx < 0.0)) { coord.Y = rhoc - xyy; s = S20; c = C20; Av = Azab; } else { coord.Y += rhoc; s = S45; c = C45; Av = Azba; } rl = rp = r = ProjectionMath.Distance(xyx, xyy); fAz = Math.Abs(Az = Math.Atan2(xyx, xyy)); for (i = NITER; i > 0; --i) { z = 2.0 * Math.Atan(Math.Pow(r / F, 1 / n)); al = Math.Acos((Math.Pow(Math.Tan(.5 * z), n) + Math.Pow(Math.Tan(.5 * (R104 - z)), n)) / T); if (fAz < al) { r = rp * Math.Cos(al + (neg ? Az : -Az)); } if (Math.Abs(rl - r) < EPS) { break; } rl = r; } if (i == 0) { throw new ProjectionException("I"); } Az = Av - Az / n; coord.Y = Math.Asin(s * Math.Cos(z) + c * Math.Sin(z) * Math.Cos(Az)); coord.X = Math.Atan2(Math.Sin(Az), c / Math.Tan(z) - s * Math.Cos(Az)); if (neg) { coord.X -= R110; } else { coord.X = lamB - coord.X; } return(coord); }
public override Coordinate ProjectInverse(double x, double y, Coordinate lp) { double rh, cosz, sinz; rh = ProjectionMath.Distance(x, y); sinz = Math.Sin(lp.Y = Math.Atan(rh)); cosz = Math.Sqrt(1.0 - sinz * sinz); if (Math.Abs(rh) <= EPS10) { lp.Y = ProjectionLatitude; lp.X = 0.0; } else { switch (Mode) { case AzimuthalMode.Oblique: lp.Y = cosz * _sinphi0 + y * sinz * _cosphi0 / rh; if (Math.Abs(lp.Y) >= 1.0) { lp.Y = lp.Y > 0.0 ? ProjectionMath.PiHalf : -ProjectionMath.PiHalf; } else { lp.Y = Math.Asin(lp.Y); } y = (cosz - _sinphi0 * Math.Sin(lp.Y)) * rh; x *= sinz * _cosphi0; break; case AzimuthalMode.Equator: lp.Y = y * sinz / rh; if (Math.Abs(lp.Y) >= 1.0) { lp.Y = lp.Y > 0.0 ? ProjectionMath.PiHalf : -ProjectionMath.PiHalf; } else { lp.Y = Math.Asin(lp.Y); } y = cosz * rh; x *= sinz; break; case AzimuthalMode.SouthPole: lp.Y -= ProjectionMath.PiHalf; break; case AzimuthalMode.NorthPole: lp.Y = ProjectionMath.PiHalf - lp.Y; y = -y; break; } lp.X = Math.Atan2(x, y); } return(lp); }
public override Coordinate ProjectInverse(double xyx, double xyy, Coordinate coord) { double rho; if ((rho = ProjectionMath.Distance(xyx, xyy = _rho0 - xyy)) != 0) { double lpphi, lplam; if (_n < 0.0) { rho = -rho; xyx = -xyx; xyy = -xyy; } lpphi = rho / _dd; if (!_spherical) { lpphi = (_c - lpphi * lpphi) / _n; if (Math.Abs(_ec - Math.Abs(lpphi)) > Tolerance7) { if ((lpphi = phi1_(lpphi, _e, _oneEs)) == Double.MaxValue) { throw new ProjectionException("I"); } } else { lpphi = lpphi < 0.0 ? -ProjectionMath.PiHalf : ProjectionMath.PiHalf; } } else if (Math.Abs(coord.Y = (_c - lpphi * lpphi) / _n2) <= 1.0) { lpphi = Math.Asin(lpphi); } else { lpphi = lpphi < 0.0 ? -ProjectionMath.PiHalf : ProjectionMath.PiHalf; } lplam = Math.Atan2(xyx, xyy) / _n; coord.X = lplam; coord.Y = lpphi; } else { coord.X = 0.0; coord.Y = _n > 0.0 ? ProjectionMath.PiHalf : -ProjectionMath.PiHalf; } return(coord); }
public override Coordinate ProjectInverse(double xyx, double xyy, Coordinate coord) { if (_spherical) { double rh = ProjectionMath.Distance(xyx, coord.Y = _cphi1 - xyy); coord.Y = _cphi1 + _phi1 - rh; if (Math.Abs(coord.Y) > ProjectionMath.PiHalf) { throw new ProjectionException("I"); } if (Math.Abs(Math.Abs(coord.Y) - ProjectionMath.PiHalf) <= EPS10) { coord.X = 0.0; } else { coord.X = rh * Math.Atan2(xyx, xyy) / Math.Cos(coord.Y); } } else { double s; double rh = ProjectionMath.Distance(xyx, coord.Y = _am1 - xyy); coord.Y = ProjectionMath.inv_mlfn(_am1 + _m1 - rh, _es, _en); if ((s = Math.Abs(coord.Y)) < ProjectionMath.PiHalf) { s = Math.Sin(coord.Y); coord.X = rh * Math.Atan2(xyx, xyy) * Math.Sqrt(1.0 - _es * s * s) / Math.Cos(coord.Y); } else if (Math.Abs(s - ProjectionMath.PiHalf) <= EPS10) { coord.X = 0.0; } else { throw new ProjectionException("I"); } } return(coord); }
public override Coordinate ProjectInverse(double x, double y, Coordinate lp) { if (Spherical) { double cosc, c_rh, sinc; if ((c_rh = ProjectionMath.Distance(x, y)) > Math.PI) { if (c_rh - EPS10 > Math.PI) { throw new ProjectionException(); } c_rh = Math.PI; } else if (c_rh < EPS10) { lp.Y = ProjectionLatitude; lp.X = 0.0; return(lp); } if (Mode == AzimuthalMode.Oblique || Mode == AzimuthalMode.Equator) { sinc = Math.Sin(c_rh); cosc = Math.Cos(c_rh); if (Mode == AzimuthalMode.Equator) { lp.Y = ProjectionMath.Asin(y * sinc / c_rh); x *= sinc; y = cosc * c_rh; } else { lp.Y = ProjectionMath.Asin(cosc * _sinphi0 + y * sinc * _cosphi0 / c_rh); y = (cosc - _sinphi0 * Math.Sin(lp.Y)) * c_rh; x *= sinc * _cosphi0; } lp.X = y == 0.0 ? 0.0 : Math.Atan2(x, y); } else if (Mode == AzimuthalMode.NorthPole) { lp.Y = ProjectionMath.PiHalf - c_rh; lp.X = Math.Atan2(x, -y); } else { lp.Y = c_rh - ProjectionMath.PiHalf; lp.X = Math.Atan2(x, y); } } else { double c, Az, cosAz, A, B, D, E, F, psi, t; int i; if ((c = ProjectionMath.Distance(x, y)) < EPS10) { lp.Y = ProjectionLatitude; lp.X = 0.0; return(lp); } if (Mode == AzimuthalMode.Oblique || Mode == AzimuthalMode.Equator) { cosAz = Math.Cos(Az = Math.Atan2(x, y)); t = _cosphi0 * cosAz; B = EccentricitySquared * t / _oneEs; A = -B * t; B *= 3.0 * (1.0 - A) * _sinphi0; D = c / _n1; E = D * (1.0 - D * D * (A * (1.0 + A) / 6.0 + B * (1.0 + 3.0 * A) * D / 24.0)); F = 1.0 - E * E * (A / 2.0 + B * E / 6.0); psi = ProjectionMath.Asin(_sinphi0 * Math.Cos(E) + t * Math.Sin(E)); lp.X = ProjectionMath.Asin(Math.Sin(Az) * Math.Sin(E) / Math.Cos(psi)); if ((t = Math.Abs(psi)) < EPS10) { lp.Y = 00.0; } else if (Math.Abs(t - ProjectionMath.PiHalf) < 0.0) { lp.Y = ProjectionMath.PiHalf; } else { lp.Y = Math.Atan((1.0 - EccentricitySquared * F * _sinphi0 / Math.Sin(psi)) * Math.Tan(psi) / _oneEs); } } else { lp.Y = ProjectionMath.inv_mlfn(Mode == AzimuthalMode.NorthPole ? _mp - c : _mp + c, EccentricitySquared, _en); lp.X = Math.Atan2(x, Mode == AzimuthalMode.NorthPole ? -y : y); } } return(lp); }
public override Coordinate ProjectInverse(double x, double y, Coordinate lp) { if (Spherical) { double c, rh, sinc, cosc; sinc = Math.Sin(c = 2.0 * Math.Atan((rh = ProjectionMath.Distance(x, y)) / _akm1)); cosc = Math.Cos(c); lp.X = 0.0; switch (Mode) { case AzimuthalMode.Equator: if (Math.Abs(rh) <= EPS10) { lp.Y = 0.0; } else { lp.Y = Math.Asin(y * sinc / rh); } if (cosc != 0.0 || x != 0.0) { lp.X = Math.Atan2(x * sinc, cosc * rh); } break; case AzimuthalMode.Oblique: if (Math.Abs(rh) <= EPS10) { lp.Y = ProjectionLatitude; } else { lp.Y = Math.Asin(cosc * _sinphi0 + y * sinc * _cosphi0 / rh); } if ((c = cosc - _sinphi0 * Math.Sin(lp.Y)) != 0.0 || x != 0.0) { lp.X = Math.Atan2(x * sinc * _cosphi0, c * rh); } break; case AzimuthalMode.NorthPole: case AzimuthalMode.SouthPole: if (Mode == AzimuthalMode.NorthPole) { y = -y; } if (Math.Abs(rh) <= EPS10) { lp.Y = ProjectionLatitude; } else { lp.Y = Math.Asin(Mode == AzimuthalMode.SouthPole ? -cosc : cosc); } lp.X = (x == 0.0 && y == 0.0) ? 0.0 : Math.Atan2(x, y); break; } } else { double cosphi, sinphi, tp, phi_l, rho, halfe, halfpi; rho = ProjectionMath.Distance(x, y); switch (Mode) { case AzimuthalMode.Oblique: case AzimuthalMode.Equator: default: // To prevent the compiler complaining about uninitialized vars. cosphi = Math.Cos(tp = 2.0 * Math.Atan2(rho * _cosphi0, _akm1)); sinphi = Math.Sin(tp); phi_l = Math.Asin(cosphi * _sinphi0 + (y * sinphi * _cosphi0 / rho)); tp = Math.Tan(.5 * (ProjectionMath.PiHalf + phi_l)); x *= sinphi; y = rho * _cosphi0 * cosphi - y * _sinphi0 * sinphi; halfpi = ProjectionMath.PiHalf; halfe = .5 * Eccentricity; break; case AzimuthalMode.NorthPole: case AzimuthalMode.SouthPole: if (Mode == AzimuthalMode.NorthPole) { y = -y; } phi_l = ProjectionMath.PiHalf - 2.0 * Math.Atan(tp = -rho / _akm1); halfpi = -ProjectionMath.PiHalf; halfe = -.5 * Eccentricity; break; } for (int i = 8; i-- != 0; phi_l = lp.Y) { sinphi = Eccentricity * Math.Sin(phi_l); lp.Y = 2.0 * Math.Atan(tp * Math.Pow((1.0 + sinphi) / (1.0 - sinphi), halfe)) - halfpi; if (Math.Abs(phi_l - lp.Y) < EPS10) { if (Mode == AzimuthalMode.SouthPole) { lp.Y = -lp.Y; } lp.X = (x == 0.0 && y == 0.0) ? 0.0 : Math.Atan2(x, y); return(lp); } } throw new ConvergenceFailureException("Iteration didn't converge"); } return(lp); }
public ProjCoordinate projectInverse(double x, double y, ProjCoordinate lp) { if (Spherical) { double cosz = 0, rh, sinz = 0; rh = ProjectionMath.Distance(x, y); if ((lp.Y = rh * .5) > 1.0) { throw new ProjectionException(); } lp.Y = 2.0 * Math.Asin(lp.Y); if (Mode == AzimuthalMode.Oblique || Mode == AzimuthalMode.Equator) { sinz = Math.Sin(lp.Y); cosz = Math.Cos(lp.Y); } switch (Mode) { case AzimuthalMode.Equator: lp.Y = Math.Abs(rh) <= EPS10 ? 0.0 : Math.Asin(y * sinz / rh); x *= sinz; y = cosz * rh; break; case AzimuthalMode.Oblique: lp.Y = Math.Abs(rh) <= EPS10 ? ProjectionLatitude : Math.Asin(cosz * _sinphi0 + y * sinz * _cosphi0 / rh); x *= sinz * _cosphi0; y = (cosz - Math.Sin(lp.Y) * _sinphi0) * rh; break; case AzimuthalMode.NorthPole: y = -y; lp.Y = ProjectionMath.PiHalf - lp.Y; break; case AzimuthalMode.SouthPole: lp.Y -= ProjectionMath.PiHalf; break; } lp.X = (y == 0.0 && (Mode == AzimuthalMode.Equator || Mode == AzimuthalMode.Oblique)) ? 0.0 : Math.Atan2(x, y); } else { double cCe, sCe, q, rho, ab = 0; switch (Mode) { case AzimuthalMode.Equator: case AzimuthalMode.Oblique: if ((rho = ProjectionMath.Distance(x /= _dd, y *= _dd)) < EPS10) { lp.X = 0.0; lp.Y = ProjectionLatitude; return(lp); } cCe = Math.Cos(sCe = 2.0 * Math.Asin(.5 * rho / _rq)); x *= (sCe = Math.Sin(sCe)); if (Mode == AzimuthalMode.Oblique) { q = _qp * (ab = cCe * _sinb1 + y * sCe * _cosb1 / rho); y = rho * _cosb1 * cCe - y * _sinb1 * sCe; } else { q = _qp * (ab = y * sCe / rho); y = rho * cCe; } break; case AzimuthalMode.NorthPole: case AzimuthalMode.SouthPole: if (Mode == AzimuthalMode.NorthPole) { y = -y; } if ((q = (x * x + y * y)) == 0) { lp.X = 0.0; lp.Y = ProjectionLatitude; return(lp); } ab = 1.0 - q / _qp; if (Mode == AzimuthalMode.SouthPole) { ab = -ab; } break; } lp.X = Math.Atan2(x, y); lp.Y = ProjectionMath.AuthLat(Math.Asin(ab), _apa); } return(lp); }