WindShift.java 1.83 KB
Newer Older
Juon Kawakami's avatar
init  
Juon Kawakami committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package firesimulator.simulator;

/**
 * @author Timo N�ssle
 *
 */
public class WindShift {

  float   speed;

  float   direction;

  float   directionDg;

  int[][] grid    = new int[4][2];

  float[] weights = new float[4];


  public WindShift( float direction, float speed, int gridSize ) {
    this.speed = speed % gridSize;
    directionDg = direction;
    direction = direction % 360;
    direction = (float) (direction / (360 / (2 * Math.PI)));
    this.direction = direction;
    float v_y = -((float) Math.cos( direction ) * speed);
    float v_x = -((float) Math.sin( direction ) * speed);
    float[][] points = new float[4][2];
    points[0][0] = v_x;
    points[0][1] = v_y;
    points[1][0] = v_x + gridSize;
    points[1][1] = v_y;
    points[2][0] = v_x + gridSize;
    points[2][1] = v_y + gridSize;
    points[3][0] = v_x;
    points[3][1] = v_y + gridSize;
    float areaTotal = gridSize * gridSize;
    for ( int c = 0; c < 4; c++ ) {
      float tx = grid[c][0] * gridSize;
      float ty = grid[c][1] * gridSize;
      float sx = points[0][0];
      float sy = points[0][1];
      float dx = gridSize - Math.abs( sx - tx );
      float dy = gridSize - Math.abs( sy - ty );
      float weight = (dx * dy) / areaTotal;
      weights[c] = weight;
    }
  }


  public float getDirection() {
    return directionDg;
  }


  public double[][] shift( double[][] source, Simulator sim ) {
    if ( speed == 0 )
      return source;
    double[][] result = new double[source.length][source[0].length];
    for ( int x = 0; x < source.length; x++ )
      for ( int y = 0; y < source[0].length; y++ ) {
        float temp = 0;
        for ( int c = 0; c < 4; c++ ) {
          temp += sim.getTempAt( x - grid[c][0], y - grid[c][1] ) * weights[c];
          System.out.println( weights[c] );
        }
        result[x][y] = temp;
      }
    return result;
  }
}