cdm/src/main/java/ucar/nc2/ft2/coverage/adapter/GeoGridCoordinate2D.java
private boolean jump2(double wantLat, double wantLon, int[] rectIndex) {
    int row = Math.max( Math.min(rectIndex[0], nrows-1), 0);
    int col = Math.max(Math.min(rectIndex[1], ncols - 1), 0);
    double lat = latEdge.get(row, col);
    double lon =  lonEdge.get(row, col);
    double diffLat = wantLat - lat;
    double diffLon = wantLon - lon;

    double dlatdy = latEdge.get(row + 1, col) - lat;
    double dlatdx = latEdge.get(row, col+1) - lat;
    double dlondx = lonEdge.get(row, col + 1) - lon;
    double dlondy = lonEdge.get(row + 1, col) - lon;

    // solve for dlon

    double dx =  (diffLon - dlondy * diffLat / dlatdy) / (dlondx - dlatdx * dlondy / dlatdy);
    // double dy =  (diffLat - dlatdx * diffLon / dlondx) / (dlatdy - dlatdx * dlondy / dlondx);
    double dy =  (diffLat - dlatdx * dx) / dlatdy;

    if (debug) System.out.printf("   jump from %d %d (dlondx=%f dlondy=%f dlatdx=%f dlatdy=%f) (diffLat,Lon=%f %f) (deltalat,Lon=%f %f)",
            row, col, dlondx, dlondy, dlatdx, dlatdy,
            diffLat, diffLon, dy, dx);

    int drow = (int) Math.round(dy);
    int dcol = (int) Math.round(dx);

    if ((drow == 0) && (dcol == 0)) {
      if (debug) System.out.printf("%n   incr:");
      return incr(wantLat, wantLon, rectIndex);
    } else {
      rectIndex[0] = Math.max( Math.min(row + drow, nrows-1), 0);
      rectIndex[1] = Math.max( Math.min(col + dcol, ncols-1), 0);
      if (debug) System.out.printf(" to (%d %d)%n", rectIndex[0], rectIndex[1]);
      if ((row == rectIndex[0]) && (col == rectIndex[1])) return false; // nothing has changed
    }

    return true;
  }
private boolean jump2(double wantLat, double wantLon, int[] rectIndex) {
    int row = Math.max( Math.min(rectIndex[0], nrows-1), 0);
    int col = Math.max(Math.min(rectIndex[1], ncols - 1), 0);
    double lat = latEdge.get(row, col);
    double lon =  lonEdge.get(row, col);
    double diffLat = wantLat - lat;
    double diffLon = wantLon - lon;

    double dlatdy = latEdge.get(row + 1, col) - lat;
    double dlatdx = latEdge.get(row, col+1) - lat;
    double dlondx = lonEdge.get(row, col + 1) - lon;
    double dlondy = lonEdge.get(row + 1, col) - lon;

    // solve for dlon

    double dx =  (diffLon - dlondy * diffLat / dlatdy) / (dlondx - dlatdx * dlondy / dlatdy);
    // double dy =  (diffLat - dlatdx * diffLon / dlondx) / (dlatdy - dlatdx * dlondy / dlondx);
    double dy =  (diffLat - dlatdx * dx) / dlatdy;

    if (debug) System.out.printf("   jump from %d %d (dlondx=%f dlondy=%f dlatdx=%f dlatdy=%f) (diffLat,Lon=%f %f) (deltalat,Lon=%f %f)",
            row, col, dlondx, dlondy, dlatdx, dlatdy,
            diffLat, diffLon, dy, dx);

    int drow = (int) Math.round(dy);
    int dcol = (int) Math.round(dx);

    if ((drow == 0) && (dcol == 0)) {
      if (debug) System.out.printf("%n   incr:");
      return incr(wantLat, wantLon, rectIndex);
    } else {
      rectIndex[0] = Math.max( Math.min(row + drow, nrows-1), 0);
      rectIndex[1] = Math.max( Math.min(col + dcol, ncols-1), 0);
      if (debug) System.out.printf(" to (%d %d)%n", rectIndex[0], rectIndex[1]);
      if ((row == rectIndex[0]) && (col == rectIndex[1])) return false; // nothing has changed
    }

    return true;
  }
private boolean jump2 ( double wantLat , double wantLon , int [ ] rectIndex ) { int row = Math . max ( Math . min ( rectIndex [ 0 ] , nrows - 1 ) , 0 ) ; int col = Math . max ( Math . min ( rectIndex [ 1 ] , ncols - 1 ) , 0 ) ; double lat = latEdge . get ( row , col ) ; double lon = lonEdge . get ( row , col ) ; double diffLat = wantLat - lat ; double diffLon = wantLon - lon ; double dlatdy = latEdge . get ( row + 1 , col ) - lat ; double dlatdx = latEdge . get ( row , col + 1 ) - lat ; double dlondx = lonEdge . get ( row , col + 1 ) - lon ; double dlondy = lonEdge . get ( row + 1 , col ) - lon ; // solve for dlon double dx = ( diffLon - dlondy * diffLat / dlatdy ) / ( dlondx - dlatdx * dlondy / dlatdy ) ; // double dy =  (diffLat - dlatdx * diffLon / dlondx) / (dlatdy - dlatdx * dlondy / dlondx); double dy = ( diffLat - dlatdx * dx ) / dlatdy ; if ( debug ) System . out . printf ( "   jump from %d %d (dlondx=%f dlondy=%f dlatdx=%f dlatdy=%f) (diffLat,Lon=%f %f) (deltalat,Lon=%f %f)" , row , col , dlondx , dlondy , dlatdx , dlatdy , diffLat , diffLon , dy , dx ) ; int drow = ( int ) Math . round ( dy ) ; int dcol = ( int ) Math . round ( dx ) ; if ( ( drow == 0 ) && ( dcol == 0 ) ) { if ( debug ) System . out . printf ( "%n   incr:" ) ; return incr ( wantLat , wantLon , rectIndex ) ; } else { rectIndex [ 0 ] = Math . max ( Math . min ( row + drow , nrows - 1 ) , 0 ) ; rectIndex [ 1 ] = Math . max ( Math . min ( col + dcol , ncols - 1 ) , 0 ) ; if ( debug ) System . out . printf ( " to (%d %d)%n" , rectIndex [ 0 ] , rectIndex [ 1 ] ) ; if ( ( row == rectIndex [ 0 ] ) && ( col == rectIndex [ 1 ] ) ) return false ; // nothing has changed } return true ; }
/*
choose x, y such that (matrix multiply) :

(wantx) = (fxx fxy)  (x)
(wanty)   (fyx fyy)  (y)

where fxx = d(fx)/dx  ~= delta lon in lon direction
where fxy = d(fx)/dy  ~= delta lon in lat direction
where fyx = d(fy)/dx  ~= delta lat in lon direction
where fyy = d(fy)/dy  ~= delta lat in lat direction

2 linear equations in 2 unknowns, solve in usual way
/ * choose x y such that ( matrix multiply ) :