Ejemplo n.º 1
0
 public ProjCoordinate project(double lplam, double lpphi, ProjCoordinate xy) {
   if (spherical) {
     xy.x = Math.asin(Math.cos(lpphi) * Math.sin(lplam));
     xy.y = Math.atan2(Math.tan(lpphi), Math.cos(lplam)) - projectionLatitude;
   } else {
     xy.y = ProjectionMath.mlfn(lpphi, n = Math.sin(lpphi), c = Math.cos(lpphi), en);
     n = 1. / Math.sqrt(1. - es * n * n);
     tn = Math.tan(lpphi);
     t = tn * tn;
     a1 = lplam * c;
     c *= es * c / (1 - es);
     a2 = a1 * a1;
     xy.x = n * a1 * (1. - a2 * t * (C1 - (8. - t + 8. * c) * a2 * C2));
     xy.y -= m0 - n * tn * a2 * (.5 + (5. - t + 6. * c) * a2 * C3);
   }
   return xy;
 }
Ejemplo n.º 2
0
  public ProjCoordinate projectInverse(double xyx, double xyy, ProjCoordinate out) {
    if (spherical) {
      out.y = Math.asin(Math.sin(dd = xyy + projectionLatitude) * Math.cos(xyx));
      out.x = Math.atan2(Math.tan(xyx), Math.cos(dd));
    } else {
      double ph1;

      ph1 = ProjectionMath.inv_mlfn(m0 + xyy, es, en);
      tn = Math.tan(ph1);
      t = tn * tn;
      n = Math.sin(ph1);
      r = 1. / (1. - es * n * n);
      n = Math.sqrt(r);
      r *= (1. - es) * n;
      dd = xyx / n;
      d2 = dd * dd;
      out.y = ph1 - (n * tn / r) * d2 * (.5 - (1. + 3. * t) * d2 * C3);
      out.x = dd * (1. + t * d2 * (-C4 + (1. + 3. * t) * d2 * C5)) / Math.cos(ph1);
    }
    return out;
  }
  public ProjCoordinate projectInverse(double x, double y, ProjCoordinate lp) {
    if (spherical) {
      double c, rh, sinc, cosc;

      sinc = Math.sin(c = 2. * Math.atan((rh = ProjectionMath.distance(x, y)) / akm1));
      cosc = Math.cos(c);
      lp.x = 0.;
      switch (mode) {
        case EQUATOR:
          if (Math.abs(rh) <= EPS10) lp.y = 0.;
          else lp.y = Math.asin(y * sinc / rh);
          if (cosc != 0. || x != 0.) lp.x = Math.atan2(x * sinc, cosc * rh);
          break;
        case 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. || x != 0.)
            lp.x = Math.atan2(x * sinc * cosphi0, c * rh);
          break;
        case NORTH_POLE:
          y = -y;
        case SOUTH_POLE:
          if (Math.abs(rh) <= EPS10) lp.y = projectionLatitude;
          else lp.y = Math.asin(mode == SOUTH_POLE ? -cosc : cosc);
          lp.x = (x == 0. && y == 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 OBLIQUE:
        case EQUATOR:
        default: // To prevent the compiler complaining about uninitialized vars.
          cosphi = Math.cos(tp = 2. * Math.atan2(rho * cosphi0, akm1));
          sinphi = Math.sin(tp);
          phi_l = Math.asin(cosphi * sinphi0 + (y * sinphi * cosphi0 / rho));
          tp = Math.tan(.5 * (ProjectionMath.HALFPI + phi_l));
          x *= sinphi;
          y = rho * cosphi0 * cosphi - y * sinphi0 * sinphi;
          halfpi = ProjectionMath.HALFPI;
          halfe = .5 * e;
          break;
        case NORTH_POLE:
          y = -y;
        case SOUTH_POLE:
          phi_l = ProjectionMath.HALFPI - 2. * Math.atan(tp = -rho / akm1);
          halfpi = -ProjectionMath.HALFPI;
          halfe = -.5 * e;
          break;
      }
      for (int i = 8; i-- != 0; phi_l = lp.y) {
        sinphi = e * Math.sin(phi_l);
        lp.y = 2. * Math.atan(tp * Math.pow((1. + sinphi) / (1. - sinphi), halfe)) - halfpi;
        if (Math.abs(phi_l - lp.y) < EPS10) {
          if (mode == SOUTH_POLE) lp.y = -lp.y;
          lp.x = (x == 0. && y == 0.) ? 0. : Math.atan2(x, y);
          return lp;
        }
      }
      throw new ConvergenceFailureException("Iteration didn't converge");
    }
    return lp;
  }