public static void normalize(Point2D.Double a) { double d = distance(a.x, a.y); a.x /= d; a.y /= d; }
public int getRowFromNearestParallel(double latitude) { int degrees = (int)MapMath.radToDeg(MapMath.normalizeLatitude(latitude)); if (degrees < -80 || degrees > 84) return 0; if (degrees > 80) return 24; return (degrees + 80) / 8 + 3; }
if ((MapMath.enfn(es)) == null) throw new IllegalArgumentException("0"); double m1 = MapMath.msfn(sinphi, cosphi, es); double ml1 = MapMath.qsfn(sinphi, e, one_es); if (secant) { /* secant cone */ sinphi = Math.sin(phi2); cosphi = Math.cos(phi2); double m2 = MapMath.msfn(sinphi, cosphi, es); double ml2 = MapMath.qsfn(sinphi, e, one_es); n = (m1 * m1 - m2 * m2) / (ml2 - ml1); c = m1 * m1 + n * ml1; dd = 1. / n; rho0 = dd * Math.sqrt(c - n * MapMath.qsfn(Math.sin(lat0rad), e, one_es));
if ((c_rh = MapMath.distance(x, y)) > Math.PI) { if (c_rh - MapMath.EPS10 > Math.PI) throw new IllegalStateException(); cosc = Math.cos(c_rh); if (mode == EQUATOR) { lp.setLatitude(Math.toDegrees(MapMath.asin(y * sinc / c_rh))); x *= sinc; y = cosc * c_rh; lp.setLatitude(Math.toDegrees(MapMath.asin(cosc * sinphi0 + y * sinc * cosphi0 / c_rh))); y = (cosc - sinphi0 * MapMath.sind(lp.getLatitude())) * c_rh; x *= sinc * cosphi0; if ((c = MapMath.distance(x, y)) < MapMath.EPS10) { lp.setLatitude(lat0); lp.setLongitude(0.0); E = D * (1. - D * D * (A * (1. + A) / 6. + B * (1. + 3. * A) * D / 24.)); F = 1. - E * E * (A / 2. + B * E / 6.); psi = MapMath.asin(sinphi0 * Math.cos(E) + t * Math.sin(E)); lp.setLongitude(Math.toDegrees(MapMath.asin(Math.sin(Az) * Math.sin(E) / Math.cos(psi)))); if ((t = Math.abs(psi)) < MapMath.EPS10) lp.setLatitude(0.0); lp.setLatitude(Math.toDegrees(Math.atan((1. - es * F * sinphi0 / Math.sin(psi)) * Math.tan(psi) / one_es))); } else { lp.setLatitude(Math.toDegrees(MapMath.inv_mlfn(mode == NORTH_POLE ? Mp - c : Mp + c, es, en))); lp.setLongitude(Math.toDegrees(Math.atan2(x, mode == NORTH_POLE ? -y : y)));
public int getZoneFromNearestMeridian(double longitude) { int zone = (int) Math.floor((MapMath.normalizeLongitude(longitude) + Math.PI) * 30.0 / Math.PI) + 1; if (zone < 1) zone = 1; else if (zone > 60) zone = 60; return zone; }
public LatLonPoint projToLatLon(ProjectionPoint world, LatLonPointImpl result) { double toLat, toLon; double fromX = (world.getX() - falseEasting) / totalScale; // assumes cartesion coords in km double fromY = (world.getY() - falseNorthing) / totalScale; fromY = rho0 - fromY; double rho = MapMath.distance(fromX, fromY); if (rho != 0) { if (n < 0.0) { rho = -rho; fromX = -fromX; fromY = -fromY; } if (isSpherical) toLat = 2.0 * Math.atan(Math.pow(c / rho, 1.0/n)) - MapMath.HALFPI; else toLat = MapMath.phi2(Math.pow(rho / c, 1.0/n), e); toLon = Math.atan2(fromX, fromY) / n; } else { toLon = 0.0; toLat = n > 0.0 ? MapMath.HALFPI : -MapMath.HALFPI; } result.setLatitude(Math.toDegrees(toLat)); result.setLongitude(Math.toDegrees(toLon) + lon0deg); return result; }
double ml1, m1; m1 = MapMath.msfn(sinphi, cosphi, es); ml1 = MapMath.tsfn(par1rad, sinphi, e); if (isSecant) { n = Math.log(m1 / MapMath.msfn(sinphi = Math.sin(par2rad), Math.cos(par2rad), es)); n /= Math.log(ml1 / MapMath.tsfn(par2rad, sinphi, e)); Math.pow(MapMath.tsfn(lat0rad, Math.sin(lat0rad), e), n);
double g = .5 * (h - 1. / h); h = Math.cos(projectionLatitude + y / scaleFactor); out.y = MapMath.asin(Math.sqrt((1. - h * h) / (1. + g * g))); if (y < 0) out.y = -out.y; double n, con, cosphi, d, ds, sinphi, t; out.y = MapMath.inv_mlfn(ml0 + y / scaleFactor, es, en); if (Math.abs(y) >= MapMath.HALFPI) { out.y = y < 0. ? -MapMath.HALFPI : MapMath.HALFPI;
private Point2D.Double project(double lplam, double lpphi, Point2D.Double out) { if (spherical) { double cot, E; if (Math.abs(lpphi) <= TOL) { out.x = lplam; out.y = ml0; } else { cot = 1. / Math.tan(lpphi); out.x = Math.sin(E = lplam * Math.sin(lpphi)) * cot; out.y = lpphi - projectionLatitude + cot * (1. - Math.cos(E)); } } else { double ms, sp, cp; if (Math.abs(lpphi) <= TOL) { out.x = lplam; out.y = -ml0; } else { sp = Math.sin(lpphi); ms = Math.abs(cp = Math.cos(lpphi)) > TOL ? MapMath.msfn(sp, cp, es) / sp : 0.; out.x = ms * Math.sin(out.x *= sp); out.y = (MapMath.mlfn(lpphi, sp, cp, en) - ml0) + ms * (1. - Math.cos(lplam)); } } return out; }
public static double inv_mlfn(double arg, double es, double[] en) { double s, t, phi, k = 1./(1.-es); phi = arg; for (int i = MAX_ITER; i != 0; i--) { s = Math.sin(phi); t = 1. - es * s * s; phi -= t = (mlfn(phi, s, Math.cos(phi), en) - arg) * (t * Math.sqrt(t)) * k; if (Math.abs(t) < 1e-11) return phi; } return phi; }
if ((c_rh = MapMath.distance(x, y)) > Math.PI) { if (c_rh - MapMath.EPS10 > Math.PI) throw new IllegalStateException(); cosc = Math.cos(c_rh); if (mode == EQUATOR) { lp.setLatitude(Math.toDegrees(MapMath.asin(y * sinc / c_rh))); x *= sinc; y = cosc * c_rh; lp.setLatitude(Math.toDegrees(MapMath.asin(cosc * sinphi0 + y * sinc * cosphi0 / c_rh))); y = (cosc - sinphi0 * MapMath.sind(lp.getLatitude())) * c_rh; x *= sinc * cosphi0; if ((c = MapMath.distance(x, y)) < MapMath.EPS10) { lp.setLatitude(lat0); lp.setLongitude(0.0); E = D * (1. - D * D * (A * (1. + A) / 6. + B * (1. + 3. * A) * D / 24.)); F = 1. - E * E * (A / 2. + B * E / 6.); psi = MapMath.asin(sinphi0 * Math.cos(E) + t * Math.sin(E)); lp.setLongitude(Math.toDegrees(MapMath.asin(Math.sin(Az) * Math.sin(E) / Math.cos(psi)))); if ((t = Math.abs(psi)) < MapMath.EPS10) lp.setLatitude(0.0); lp.setLatitude(Math.toDegrees(Math.atan((1. - es * F * sinphi0 / Math.sin(psi)) * Math.tan(psi) / one_es))); } else { lp.setLatitude(Math.toDegrees(MapMath.inv_mlfn(mode == NORTH_POLE ? Mp - c : Mp + c, es, en))); lp.setLongitude(Math.toDegrees(Math.atan2(x, mode == NORTH_POLE ? -y : y)));
if ((MapMath.enfn(es)) == null) throw new IllegalArgumentException("0"); double m1 = MapMath.msfn(sinphi, cosphi, es); double ml1 = MapMath.qsfn(sinphi, e, one_es); if (secant) { /* secant cone */ sinphi = Math.sin(phi2); cosphi = Math.cos(phi2); double m2 = MapMath.msfn(sinphi, cosphi, es); double ml2 = MapMath.qsfn(sinphi, e, one_es); n = (m1 * m1 - m2 * m2) / (ml2 - ml1); c = m1 * m1 + n * ml1; dd = 1. / n; rho0 = dd * Math.sqrt(c - n * MapMath.qsfn(Math.sin(lat0rad), e, one_es));
public int getZoneFromNearestMeridian(double longitude) { int zone = (int)Math.floor((MapMath.normalizeLongitude(longitude) + Math.PI) * 30.0 / Math.PI) + 1; if (zone < 1) zone = 1; else if (zone > 60) zone = 60; return zone; }
public int getRowFromNearestParallel(double latitude) { int degrees = (int) MapMath.radToDeg(MapMath.normalizeLatitude(latitude)); if (degrees < -80 || degrees > 84) return 0; if (degrees > 80) return 24; return (degrees + 80) / 8 + 3; }
public LatLonPoint projToLatLon(ProjectionPoint world, LatLonPointImpl result) { double toLat, toLon; double fromX = (world.getX() - falseEasting) / totalScale; // assumes cartesion coords in km double fromY = (world.getY() - falseNorthing) / totalScale; fromY = rho0 - fromY; double rho = MapMath.distance(fromX, fromY); if (rho != 0) { if (n < 0.0) { rho = -rho; fromX = -fromX; fromY = -fromY; } if (isSpherical) toLat = 2.0 * Math.atan(Math.pow(c / rho, 1.0/n)) - MapMath.HALFPI; else toLat = MapMath.phi2(Math.pow(rho / c, 1.0/n), e); toLon = Math.atan2(fromX, fromY) / n; //coverity[swapped_arguments] } else { toLon = 0.0; toLat = n > 0.0 ? MapMath.HALFPI : -MapMath.HALFPI; } result.setLatitude(Math.toDegrees(toLat)); result.setLongitude(Math.toDegrees(toLon) + lon0deg); return result; }
double ml1, m1; m1 = MapMath.msfn(sinphi, cosphi, es); ml1 = MapMath.tsfn(par1rad, sinphi, e); if (isSecant) { n = Math.log(m1 / MapMath.msfn(sinphi = Math.sin(par2rad), Math.cos(par2rad), es)); n /= Math.log(ml1 / MapMath.tsfn(par2rad, sinphi, e)); Math.pow(MapMath.tsfn(lat0rad, Math.sin(lat0rad), e), n);
double g = .5 * (h - 1. / h); h = Math.cos(projectionLatitude + y / scaleFactor); out.y = MapMath.asin(Math.sqrt((1. - h*h) / (1. + g*g))); if (y < 0) out.y = -out.y; double n, con, cosphi, d, ds, sinphi, t; out.y = MapMath.inv_mlfn(ml0 + y/scaleFactor, es, en); if (Math.abs(y) >= MapMath.HALFPI) { out.y = y < 0. ? -MapMath.HALFPI : MapMath.HALFPI;