void CalcBins4Map(double Range){
  int ad=0;
  if (Range % this.LagSize == 0) {
    ad=0;
  }
  bin[][] bins1=new bin[(int)Math.ceil(Range / this.LagSize) + ad][(int)Math.ceil(Range / this.LagSize + ad)];
  bin[][] bins4=new bin[(int)Math.ceil(Range / this.LagSize) + ad][(int)Math.ceil(Range / this.LagSize + ad)];
  bin[][] bins1c=new bin[(int)Math.ceil(Range / this.LagSize) + ad][(int)Math.ceil(Range / this.LagSize + ad)];
  bin[][] bins4c=new bin[(int)Math.ceil(Range / this.LagSize) + ad][(int)Math.ceil(Range / this.LagSize + ad)];
  BinSurface=new bin[2 * ((int)Math.ceil(Range / this.LagSize) + ad)][2 * ((int)Math.ceil(Range / this.LagSize + ad))];
  double radious=this.LagSize * 2 / Math.sqrt(2);
  double halfLagSize=this.LagSize;
  List<pair> prs=new ArrayList();
  double w=0;
  for (int r=0; r < bins1.length; r++) {
    for (int c=0; c < bins1[r].length; c++) {
      if (bins1[r][c] == null) {
        bin bb=new bin();
        bin bbc=new bin();
        bins1[r][c]=bb;
        bins1c[r][c]=bbc;
      }
      bins1[r][c].GridHorDistance=0.5 * this.LagSize + c * this.LagSize;
      bins1[r][c].GridVerDistance=0.5 * this.LagSize + r * this.LagSize;
      bins1c[r][c].GridHorDistance=-0.5 * this.LagSize - c * this.LagSize;
      bins1c[r][c].GridVerDistance=-0.5 * this.LagSize - r * this.LagSize;
      double[] center=new double[]{bins1[r][c].GridVerDistance,bins1[r][c].GridHorDistance};
      prs=getBinNNPairs4Map(PairsTree,center,halfLagSize,radious);
      for (int n=0; n < prs.size(); n++) {
        bins1[r][c].HorDistance+=prs.get(n).HorDistance;
        bins1[r][c].VerDistance+=prs.get(n).VerDistance;
        w=(1 - (Math.abs(bins1[r][c].GridHorDistance - prs.get(n).HorDistance) / this.LagSize)) * (1 - (Math.abs(bins1[r][c].GridVerDistance - prs.get(n).VerDistance) / this.LagSize));
        bins1[r][c].Weight+=w;
        bins1[r][c].Value+=prs.get(n).MomentI * w;
        bins1[r][c].Size+=1;
        bins1c[r][c].HorDistance+=prs.get(n).HorDistance;
        bins1c[r][c].VerDistance+=prs.get(n).VerDistance;
        bins1c[r][c].Weight+=w;
        bins1c[r][c].Value+=prs.get(n).MomentI * w;
        bins1c[r][c].Size+=1;
      }
    }
  }
  for (int i=0; i < bins1.length; i++) {
    for (int j=0; j < bins1[i].length; j++) {
      if (bins1[i][j] == null) {
        bin bb=new bin();
        bins1[i][j]=bb;
        bins1[i][j].HorDistance=i * this.LagSize;
        bins1[i][j].VerDistance=j * this.LagSize;
        bins1[i][j].Value=-1;
        bin bbc=new bin();
        bins1c[i][j]=bbc;
        bins1c[i][j].HorDistance=-i * this.LagSize;
        bins1c[i][j].VerDistance=-j * this.LagSize;
        bins1c[i][j].Value=-1;
      }
 else {
        bins1[i][j].HorDistance=bins1[i][j].HorDistance / bins1[i][j].Size;
        bins1[i][j].VerDistance=bins1[i][j].VerDistance / bins1[i][j].Size;
        bins1[i][j].Value=bins1[i][j].Value / bins1[i][j].Weight;
        bins1c[i][j].HorDistance=bins1c[i][j].HorDistance / bins1c[i][j].Size;
        bins1c[i][j].VerDistance=bins1c[i][j].VerDistance / bins1c[i][j].Size;
        bins1c[i][j].Value=bins1c[i][j].Value / bins1c[i][j].Weight;
      }
    }
  }
  for (int r=0; r < bins4.length; r++) {
    for (int c=0; c < bins4[r].length; c++) {
      if (bins4[r][c] == null) {
        bin bb=new bin();
        bin bbc=new bin();
        bins4[r][c]=bb;
        bins4c[r][c]=bbc;
      }
      bins4[r][c].GridHorDistance=0.5 * this.LagSize + c * this.LagSize;
      bins4[r][c].GridVerDistance=-0.5 * this.LagSize - r * this.LagSize;
      bins4c[r][c].GridHorDistance=-0.5 * this.LagSize - c * this.LagSize;
      bins4c[r][c].GridVerDistance=0.5 * this.LagSize + r * this.LagSize;
      double[] center=new double[]{bins4[r][c].GridVerDistance,bins4[r][c].GridHorDistance};
      prs=getBinNNPairs4Map(PairsTree,center,halfLagSize,radious);
      for (int n=0; n < prs.size(); n++) {
        bins4[r][c].HorDistance+=prs.get(n).HorDistance;
        bins4[r][c].VerDistance+=prs.get(n).VerDistance;
        w=(1 - (Math.abs(bins4[r][c].GridHorDistance - prs.get(n).HorDistance) / this.LagSize)) * (1 - (Math.abs(bins4[r][c].GridVerDistance - prs.get(n).VerDistance) / this.LagSize));
        bins4[r][c].Weight+=w;
        bins4[r][c].Value+=prs.get(n).MomentI * w;
        bins4[r][c].Size+=1;
        bins4c[r][c].HorDistance+=prs.get(n).HorDistance;
        bins4c[r][c].VerDistance+=prs.get(n).VerDistance;
        bins4c[r][c].Weight+=w;
        bins4c[r][c].Value+=prs.get(n).MomentI * w;
        bins4c[r][c].Size+=1;
      }
    }
  }
  for (int i=0; i < bins4.length; i++) {
    for (int j=0; j < bins4[i].length; j++) {
      if (bins4[i][j] == null) {
        bin bb=new bin();
        bins4[i][j]=bb;
        bins4[i][j].HorDistance=i * this.LagSize;
        bins4[i][j].VerDistance=j * this.LagSize;
        bins4[i][j].Value=-1;
        bin bbc=new bin();
        bins4c[i][j]=bbc;
        bins4c[i][j].HorDistance=-i * this.LagSize;
        bins4c[i][j].VerDistance=-j * this.LagSize;
        bins4c[i][j].Value=-1;
      }
 else {
        bins4[i][j].HorDistance=bins4[i][j].HorDistance / bins4[i][j].Size;
        bins4[i][j].VerDistance=bins4[i][j].VerDistance / bins4[i][j].Size;
        bins4[i][j].Value=bins4[i][j].Value / bins4[i][j].Weight;
        bins4c[i][j].HorDistance=bins4c[i][j].HorDistance / bins4c[i][j].Size;
        bins4c[i][j].VerDistance=bins4c[i][j].VerDistance / bins4c[i][j].Size;
        bins4c[i][j].Value=bins4c[i][j].Value / bins4c[i][j].Weight;
      }
    }
  }
  int stI=BinSurface.length / 2;
  int stJ=BinSurface[0].length / 2;
  for (int i=0; i < bins1.length; i++) {
    for (int j=0; j < bins1[i].length; j++) {
      BinSurface[stI + i][stJ + j]=bins1[i][j];
      BinSurface[stI - 1 - i][stJ - 1 - j]=bins1c[i][j];
    }
  }
  stI=BinSurface.length / 2;
  stJ=BinSurface[0].length / 2;
  for (int i=0; i < bins4.length; i++) {
    for (int j=0; j < bins4[i].length; j++) {
      BinSurface[stI - 1 - i][stJ + j]=bins4[i][j];
      BinSurface[stI + i][stJ - 1 - j]=bins4c[i][j];
    }
  }
  int resd=0;
}

void CalcBins4Map ( double Range ) { int ad = 0 ; if ( Range % this . LagSize == 0 ) { ad = 0 ; } bin [ ] [ ] bins1 = new bin [ ( int ) Math . ceil ( Range / this . LagSize ) + ad ] [ ( int ) Math . ceil ( Range / this . LagSize + ad ) ] ; bin [ ] [ ] bins4 = new bin [ ( int ) Math . ceil ( Range / this . LagSize ) + ad ] [ ( int ) Math . ceil ( Range / this . LagSize + ad ) ] ; bin [ ] [ ] bins1c = new bin [ ( int ) Math . ceil ( Range / this . LagSize ) + ad ] [ ( int ) Math . ceil ( Range / this . LagSize + ad ) ] ; bin [ ] [ ] bins4c = new bin [ ( int ) Math . ceil ( Range / this . LagSize ) + ad ] [ ( int ) Math . ceil ( Range / this . LagSize + ad ) ] ; BinSurface = new bin [ 2 * ( ( int ) Math . ceil ( Range / this . LagSize ) + ad ) ] [ 2 * ( ( int ) Math . ceil ( Range / this . LagSize + ad ) ) ] ; double radious = this . LagSize * 2 / Math . sqrt ( 2 ) ; double halfLagSize = this . LagSize ; List < pair > prs = new ArrayList ( ) ; double w = 0 ; for ( int r = 0 ; r < bins1 . length ; r ++ ) { for ( int c = 0 ; c < bins1 [ r ] . length ; c ++ ) { if ( bins1 [ r ] [ c ] == null ) { bin bb = new bin ( ) ; bin bbc = new bin ( ) ; bins1 [ r ] [ c ] = bb ; bins1c [ r ] [ c ] = bbc ; } bins1 [ r ] [ c ] . GridHorDistance = 0.5 * this . LagSize + c * this . LagSize ; bins1 [ r ] [ c ] . GridVerDistance = 0.5 * this . LagSize + r * this . LagSize ; bins1c [ r ] [ c ] . GridHorDistance = - 0.5 * this . LagSize - c * this . LagSize ; bins1c [ r ] [ c ] . GridVerDistance = - 0.5 * this . LagSize - r * this . LagSize ; double [ ] center = new double [ ] { bins1 [ r ] [ c ] . GridVerDistance , bins1 [ r ] [ c ] . GridHorDistance } ; prs = getBinNNPairs4Map ( PairsTree , center , halfLagSize , radious ) ; for ( int n = 0 ; n < prs . size ( ) ; n ++ ) { bins1 [ r ] [ c ] . HorDistance += prs . get ( n ) . HorDistance ; bins1 [ r ] [ c ] . VerDistance += prs . get ( n ) . VerDistance ; w = ( 1 - ( Math . abs ( bins1 [ r ] [ c ] . GridHorDistance - prs . get ( n ) . HorDistance ) / this . LagSize ) ) * ( 1 - ( Math . abs ( bins1 [ r ] [ c ] . GridVerDistance - prs . get ( n ) . VerDistance ) / this . LagSize ) ) ; bins1 [ r ] [ c ] . Weight += w ; bins1 [ r ] [ c ] . Value += prs . get ( n ) . MomentI * w ; bins1 [ r ] [ c ] . Size += 1 ; bins1c [ r ] [ c ] . HorDistance += prs . get ( n ) . HorDistance ; bins1c [ r ] [ c ] . VerDistance += prs . get ( n ) . VerDistance ; bins1c [ r ] [ c ] . Weight += w ; bins1c [ r ] [ c ] . Value += prs . get ( n ) . MomentI * w ; bins1c [ r ] [ c ] . Size += 1 ; } } } for ( int i = 0 ; i < bins1 . length ; i ++ ) { for ( int j = 0 ; j < bins1 [ i ] . length ; j ++ ) { if ( bins1 [ i ] [ j ] == null ) { bin bb = new bin ( ) ; bins1 [ i ] [ j ] = bb ; bins1 [ i ] [ j ] . HorDistance = i * this . LagSize ; bins1 [ i ] [ j ] . VerDistance = j * this . LagSize ; bins1 [ i ] [ j ] . Value = - 1 ; bin bbc = new bin ( ) ; bins1c [ i ] [ j ] = bbc ; bins1c [ i ] [ j ] . HorDistance = - i * this . LagSize ; bins1c [ i ] [ j ] . VerDistance = - j * this . LagSize ; bins1c [ i ] [ j ] . Value = - 1 ; } else { bins1 [ i ] [ j ] . HorDistance = bins1 [ i ] [ j ] . HorDistance / bins1 [ i ] [ j ] . Size ; bins1 [ i ] [ j ] . VerDistance = bins1 [ i ] [ j ] . VerDistance / bins1 [ i ] [ j ] . Size ; bins1 [ i ] [ j ] . Value = bins1 [ i ] [ j ] . Value / bins1 [ i ] [ j ] . Weight ; bins1c [ i ] [ j ] . HorDistance = bins1c [ i ] [ j ] . HorDistance / bins1c [ i ] [ j ] . Size ; bins1c [ i ] [ j ] . VerDistance = bins1c [ i ] [ j ] . VerDistance / bins1c [ i ] [ j ] . Size ; bins1c [ i ] [ j ] . Value = bins1c [ i ] [ j ] . Value / bins1c [ i ] [ j ] . Weight ; } } } for ( int r = 0 ; r < bins4 . length ; r ++ ) { for ( int c = 0 ; c < bins4 [ r ] . length ; c ++ ) { if ( bins4 [ r ] [ c ] == null ) { bin bb = new bin ( ) ; bin bbc = new bin ( ) ; bins4 [ r ] [ c ] = bb ; bins4c [ r ] [ c ] = bbc ; } bins4 [ r ] [ c ] . GridHorDistance = 0.5 * this . LagSize + c * this . LagSize ; bins4 [ r ] [ c ] . GridVerDistance = - 0.5 * this . LagSize - r * this . LagSize ; bins4c [ r ] [ c ] . GridHorDistance = - 0.5 * this . LagSize - c * this . LagSize ; bins4c [ r ] [ c ] . GridVerDistance = 0.5 * this . LagSize + r * this . LagSize ; double [ ] center = new double [ ] { bins4 [ r ] [ c ] . GridVerDistance , bins4 [ r ] [ c ] . GridHorDistance } ; prs = getBinNNPairs4Map ( PairsTree , center , halfLagSize , radious ) ; for ( int n = 0 ; n < prs . size ( ) ; n ++ ) { bins4 [ r ] [ c ] . HorDistance += prs . get ( n ) . HorDistance ; bins4 [ r ] [ c ] . VerDistance += prs . get ( n ) . VerDistance ; w = ( 1 - ( Math . abs ( bins4 [ r ] [ c ] . GridHorDistance - prs . get ( n ) . HorDistance ) / this . LagSize ) ) * ( 1 - ( Math . abs ( bins4 [ r ] [ c ] . GridVerDistance - prs . get ( n ) . VerDistance ) / this . LagSize ) ) ; bins4 [ r ] [ c ] . Weight += w ; bins4 [ r ] [ c ] . Value += prs . get ( n ) . MomentI * w ; bins4 [ r ] [ c ] . Size += 1 ; bins4c [ r ] [ c ] . HorDistance += prs . get ( n ) . HorDistance ; bins4c [ r ] [ c ] . VerDistance += prs . get ( n ) . VerDistance ; bins4c [ r ] [ c ] . Weight += w ; bins4c [ r ] [ c ] . Value += prs . get ( n ) . MomentI * w ; bins4c [ r ] [ c ] . Size += 1 ; } } } for ( int i = 0 ; i < bins4 . length ; i ++ ) { for ( int j = 0 ; j < bins4 [ i ] . length ; j ++ ) { if ( bins4 [ i ] [ j ] == null ) { bin bb = new bin ( ) ; bins4 [ i ] [ j ] = bb ; bins4 [ i ] [ j ] . HorDistance = i * this . LagSize ; bins4 [ i ] [ j ] . VerDistance = j * this . LagSize ; bins4 [ i ] [ j ] . Value = - 1 ; bin bbc = new bin ( ) ; bins4c [ i ] [ j ] = bbc ; bins4c [ i ] [ j ] . HorDistance = - i * this . LagSize ; bins4c [ i ] [ j ] . VerDistance = - j * this . LagSize ; bins4c [ i ] [ j ] . Value = - 1 ; } else { bins4 [ i ] [ j ] . HorDistance = bins4 [ i ] [ j ] . HorDistance / bins4 [ i ] [ j ] . Size ; bins4 [ i ] [ j ] . VerDistance = bins4 [ i ] [ j ] . VerDistance / bins4 [ i ] [ j ] . Size ; bins4 [ i ] [ j ] . Value = bins4 [ i ] [ j ] . Value / bins4 [ i ] [ j ] . Weight ; bins4c [ i ] [ j ] . HorDistance = bins4c [ i ] [ j ] . HorDistance / bins4c [ i ] [ j ] . Size ; bins4c [ i ] [ j ] . VerDistance = bins4c [ i ] [ j ] . VerDistance / bins4c [ i ] [ j ] . Size ; bins4c [ i ] [ j ] . Value = bins4c [ i ] [ j ] . Value / bins4c [ i ] [ j ] . Weight ; } } } int stI = BinSurface . length / 2 ; int stJ = BinSurface [ 0 ] . length / 2 ; for ( int i = 0 ; i < bins1 . length ; i ++ ) { for ( int j = 0 ; j < bins1 [ i ] . length ; j ++ ) { BinSurface [ stI + i ] [ stJ + j ] = bins1 [ i ] [ j ] ; BinSurface [ stI - 1 - i ] [ stJ - 1 - j ] = bins1c [ i ] [ j ] ; } } stI = BinSurface . length / 2 ; stJ = BinSurface [ 0 ] . length / 2 ; for ( int i = 0 ; i < bins4 . length ; i ++ ) { for ( int j = 0 ; j < bins4 [ i ] . length ; j ++ ) { BinSurface [ stI - 1 - i ] [ stJ + j ] = bins4 [ i ] [ j ] ; BinSurface [ stI + i ] [ stJ - 1 - j ] = bins4c [ i ] [ j ] ; } } int resd = 0 ; }
calculates the bin list for sv map
