Beispiel #1
0
  private void renderBlackout(Graphics g, int x, int y, int radius) {
    if (radius > 320) return;

    int[] xp = new int[20];
    int[] yp = new int[20];
    for (int i = 0; i < 16; i++) {
      xp[i] = x + (int) (Math.cos(i * Math.PI / 15) * radius);
      yp[i] = y + (int) (Math.sin(i * Math.PI / 15) * radius);
    }
    xp[16] = 320;
    yp[16] = y;
    xp[17] = 320;
    yp[17] = 240;
    xp[18] = 0;
    yp[18] = 240;
    xp[19] = 0;
    yp[19] = y;
    g.fillPolygon(xp, yp, xp.length);

    for (int i = 0; i < 16; i++) {
      xp[i] = x - (int) (Math.cos(i * Math.PI / 15) * radius);
      yp[i] = y - (int) (Math.sin(i * Math.PI / 15) * radius);
    }
    xp[16] = 320;
    yp[16] = y;
    xp[17] = 320;
    yp[17] = 0;
    xp[18] = 0;
    yp[18] = 0;
    xp[19] = 0;
    yp[19] = y;

    g.fillPolygon(xp, yp, xp.length);
  }
  /* CALCULATE COORDINATES: Determine new x-y coords given a start x-y and
  a distance and direction */
  public static void calcCoords(int index, int x, int y, double dist, double dirn) {
    while (dirn < 0.0) dirn = 360.0 + dirn;
    while (dirn > 360.0) dirn = dirn - 360.0;
    // System.out.println("dirn = " + dirn);

    // North-East
    if (dirn <= 90.0) {
      xValues[index] = x + (int) (Math.sin(Math.toRadians(dirn)) * dist);
      yValues[index] = y - (int) (Math.cos(Math.toRadians(dirn)) * dist);
      return;
    }
    // South-East
    if (dirn <= 180.0) {
      xValues[index] = x + (int) (Math.cos(Math.toRadians(dirn - 90)) * dist);
      yValues[index] = y + (int) (Math.sin(Math.toRadians(dirn - 90)) * dist);
      return;
    }
    // South-West
    if (dirn <= 90.0) {
      xValues[index] = x - (int) (Math.sin(Math.toRadians(dirn - 180)) * dist);
      yValues[index] = y + (int) (Math.cos(Math.toRadians(dirn - 180)) * dist);
    }
    // Nort-West
    else {
      xValues[index] = x - (int) (Math.cos(Math.toRadians(dirn - 270)) * dist);
      yValues[index] = y - (int) (Math.sin(Math.toRadians(dirn - 270)) * dist);
    }
  }
Beispiel #3
0
  /*======== public void generateSphere() ==========
      Inputs:   double cx
                double cy
  double r
  double step
      Returns:

      Generates all the points along the surface of a
      sphere with center (cx, cy) and radius r

      Adds these points to the matrix parameter

      jonalf
      ====================*/
  public void generateSphere(double cx, double cy, double r, double step) {
    double f, t;
    for (f = 0; f < 1; f += step) {
      for (t = 0; t < 1; t += step) {
        double x = r * Math.cos(Math.PI * 2 * t) + cx;
        double y = r * Math.sin(Math.PI * 2 * t) * Math.cos(Math.PI * f) + cy;
        double z = r * Math.sin(Math.PI * 2 * t) * Math.sin(Math.PI * f);
        addPoint(x, y, z);
      }
    }
  }
Beispiel #4
0
  /*======== public void generateTorus() ==========
      Inputs:   double cx
                double cy
  double r1
  double r2
  double step
      Returns:

      Generates all the points along the surface of a
      tarus with center (cx, cy) and radii r1 and r2

      Adds these points to the matrix parameter

      jonalf
      ====================*/
  public void generateTorus(double cx, double cy, double r1, double r2, double step) {
    double f, t;
    for (f = 0; f < 1; f += step) {
      for (t = 0; t < 1; t += step) {
        double x = Math.cos(Math.PI * 2 * f) * (r2 * Math.cos(Math.PI * 2 * t) + r1) + cx;
        double y = r2 * Math.sin(Math.PI * 2 * t) + cy;
        double z = -1 * Math.sin(Math.PI * 2 * f) * (r2 * Math.cos(Math.PI * 2 * t) + r1);
        addPoint(x, y, z);
      }
    }
  }
  public void move() {
    if (last_move_time == null || last_move_time.doubleValue() < world.time) {
      last_move_time = new Double(world.time);
      double max_dist, dist_right, dist_left, theta, x, y, dist_diff;
      double delta_theta, turn_radius, new_theta, new_x, new_y;
      Location location;
      Orientation orientation;

      orientation = orientation();
      location = location();

      max_dist = max_speed / world.ticks_per_second;
      dist_right = right_motor.output() * max_dist;
      dist_left = left_motor.output() * max_dist;
      theta = orientation.theta;
      x = location.x;
      y = location.y;
      old_location.x = x;
      old_location.y = y;
      dist_diff = dist_right - dist_left;

      //			System.out.println("dist_diff: " + dist_diff);

      delta_theta = dist_diff / wheel_base;
      if (Math.abs(dist_diff) < .0001) {
        turn_radius = 0.0;
      } else {
        turn_radius = (dist_right / delta_theta) - (wheel_base / 2);
      }

      //			System.out.println("turn_radius: " + turn_radius);

      new_theta = theta + delta_theta;
      if (turn_radius == 0.0) {

        //				System.out.println("turn_radius == 0");

        new_x = x + Math.cos(theta) * dist_left;
        new_y = y + Math.sin(theta) * dist_left;
      } else {

        //				System.out.println("new_theta= " + new_theta + " theta= " + theta);

        new_x = x + ((Math.sin(new_theta) - Math.sin(theta)) * turn_radius);
        new_y = y - ((Math.cos(new_theta) - Math.cos(theta)) * turn_radius);
      }
      orientation.theta = new_theta;
      location.x = new_x;
      location.y = new_y;

      maybe_fire_guns();
    }
  }
Beispiel #6
0
  // For now the final output is unusable.  The associated quantization step
  // needs some tweaking.  If you get this part working, please let me know.
  public double[][] forwardDCTExtreme(float[][] input) {
    double[][] output = new double[N][N];
    double tmp0;
    double tmp1;
    double tmp2;
    double tmp3;
    double tmp4;
    double tmp5;
    double tmp6;
    double tmp7;
    double tmp10;
    double tmp11;
    double tmp12;
    double tmp13;
    double z1;
    double z2;
    double z3;
    double z4;
    double z5;
    double z11;
    double z13;
    int i;
    int j;
    int v;
    int u;
    int x;
    int y;

    for (v = 0; v < 8; v++) {
      for (u = 0; u < 8; u++) {
        for (x = 0; x < 8; x++) {
          for (y = 0; y < 8; y++) {
            output[v][u] +=
                (((double) input[x][y])
                    * Math.cos(((double) ((2 * x) + 1) * (double) u * Math.PI) / (double) 16)
                    * Math.cos(((double) ((2 * y) + 1) * (double) v * Math.PI) / (double) 16));
          }
        }

        output[v][u] *=
            ((double) (0.25)
                * ((u == 0) ? ((double) 1.0 / Math.sqrt(2)) : (double) 1.0)
                * ((v == 0) ? ((double) 1.0 / Math.sqrt(2)) : (double) 1.0));
      }
    }

    return output;
  }
Beispiel #7
0
 /**
  * Apply this operator (function) to the supplied argument
  *
  * @param value the argument
  * @return the result
  */
 protected double applyFunction(double value) {
   switch (m_operator) {
     case 'l':
       return Math.log(value);
     case 'b':
       return Math.abs(value);
     case 'c':
       return Math.cos(value);
     case 'e':
       return Math.exp(value);
     case 's':
       return Math.sqrt(value);
     case 'f':
       return Math.floor(value);
     case 'h':
       return Math.ceil(value);
     case 'r':
       return Math.rint(value);
     case 't':
       return Math.tan(value);
     case 'n':
       return Math.sin(value);
   }
   return Double.NaN;
 }
Beispiel #8
0
 /** Draw a string with letters that move up and down individually. */
 public void drawWavyString(
     String s,
     int x,
     int y,
     int align,
     int increment_x,
     double tmr,
     double amplitude,
     double pos_phaseshift,
     double timer_phaseshift,
     JGFont font,
     JGColor col) {
   setFont(font);
   setColor(col);
   if (align == 0) {
     x -= increment_x * s.length() / 2;
   } else if (align == 1) {
     x -= increment_x * s.length();
   }
   for (int i = 0; i < s.length(); i++)
     drawString(
         s.substring(i, i + 1),
         x + i * increment_x,
         y
             + (int)
                 (amplitude * -Math.cos(Math.PI * (pos_phaseshift * i + tmr * timer_phaseshift))),
         0);
 }
Beispiel #9
0
  public void method352(
      int i, int j, int ai[], int k, int ai1[], int i1, int j1, int k1, int l1, int i2) {
    try {
      int j2 = -l1 / 2;
      int k2 = -i / 2;
      int l2 = (int) (Math.sin((double) j / 326.11000000000001D) * 65536D);
      int i3 = (int) (Math.cos((double) j / 326.11000000000001D) * 65536D);
      l2 = l2 * k >> 8;
      i3 = i3 * k >> 8;
      int j3 = (i2 << 16) + (k2 * l2 + j2 * i3);
      int k3 = (i1 << 16) + (k2 * i3 - j2 * l2);
      int l3 = k1 + j1 * DrawingArea.width;
      for (j1 = 0; j1 < i; j1++) {
        int i4 = ai1[j1];
        int j4 = l3 + i4;
        int k4 = j3 + i3 * i4;
        int l4 = k3 - l2 * i4;
        for (k1 = -ai[j1]; k1 < 0; k1++) {
          DrawingArea.pixels[j4++] = myPixels[(k4 >> 16) + (l4 >> 16) * myWidth];
          k4 += i3;
          l4 -= l2;
        }

        j3 += l2;
        k3 += i3;
        l3 += DrawingArea.width;
      }

    } catch (Exception _ex) {
    }
  }
Beispiel #10
0
  public static double qt(double p, double ndf, boolean lower_tail) {
    // Algorithm 396: Student's t-quantiles by
    // G.W. Hill CACM 13(10), 619-620, October 1970
    if (p <= 0 || p >= 1 || ndf < 1)
      throw new IllegalArgumentException("Invalid p or df in call to qt(double,double,boolean).");
    double eps = 1e-12;
    double M_PI_2 = 1.570796326794896619231321691640; // pi/2
    boolean neg;
    double P, q, prob, a, b, c, d, y, x;
    if ((lower_tail && p > 0.5) || (!lower_tail && p < 0.5)) {
      neg = false;
      P = 2 * (lower_tail ? (1 - p) : p);
    } else {
      neg = true;
      P = 2 * (lower_tail ? p : (1 - p));
    }

    if (Math.abs(ndf - 2) < eps) {
        /* df ~= 2 */
      q = Math.sqrt(2 / (P * (2 - P)) - 2);
    } else if (ndf < 1 + eps) {
        /* df ~= 1 */
      prob = P * M_PI_2;
      q = Math.cos(prob) / Math.sin(prob);
    } else {
        /*-- usual case;  including, e.g.,  df = 1.1 */
      a = 1 / (ndf - 0.5);
      b = 48 / (a * a);
      c = ((20700 * a / b - 98) * a - 16) * a + 96.36;
      d = ((94.5 / (b + c) - 3) / b + 1) * Math.sqrt(a * M_PI_2) * ndf;
      y = Math.pow(d * P, 2 / ndf);
      if (y > 0.05 + a) {
        /* Asymptotic inverse expansion about normal */
        x = qnorm(0.5 * P, false);
        y = x * x;
        if (ndf < 5) c += 0.3 * (ndf - 4.5) * (x + 0.6);
        c = (((0.05 * d * x - 5) * x - 7) * x - 2) * x + b + c;
        y = (((((0.4 * y + 6.3) * y + 36) * y + 94.5) / c - y - 3) / b + 1) * x;
        y = a * y * y;
        if (y > 0.002) /* FIXME: This cutoff is machine-precision dependent*/ y = Math.exp(y) - 1;
        else {
            /* Taylor of    e^y -1 : */
          y = (0.5 * y + 1) * y;
        }
      } else {
        y =
            ((1 / (((ndf + 6) / (ndf * y) - 0.089 * d - 0.822) * (ndf + 2) * 3) + 0.5 / (ndf + 4))
                            * y
                        - 1)
                    * (ndf + 1)
                    / (ndf + 2)
                + 1 / y;
      }
      q = Math.sqrt(ndf * y);
    }
    if (neg) q = -q;
    return q;
  }
  void wride() throws Exception {
    out = new PrintWriter(new BufferedOutputStream(new FileOutputStream("output.txt")));
    double ans = 0;
    double di = (Math.sin(B + Math.PI * A) / A) - Math.sin(B) / A;

    for (int i = 1; i < n; i++) {
      ans += (mx[i] - mx[i - 1]) * Math.cos(A * ((mx[i - 1] + mx[i]) / 2) + B);
    }

    out.println("CHIP  " + ans);
    out.println("Integral  " + di);
    out.close();
  }
 public void loseCoins() {
   int x = player1.getX();
   int y = player1.getY();
   double losePercentage = 0.1;
   for (int i = 0;
       i < (int) coins * losePercentage;
       i++) { // makes the user lose 10 percent of the coin and draws them in a circle
     // System.out.println(i);
     int xPos = x + (int) (100 * Math.cos(Math.toRadians((360 / (coins * losePercentage)) * i)));
     int yPos = y - (int) (100 * Math.sin(Math.toRadians((360 / (coins * losePercentage)) * i)));
     coinList.add(new Coin(xPos, yPos, 3));
   }
   coins -= (int) (coins * losePercentage);
 }
Beispiel #13
0
  protected void recalcOutFreq() {
    if (inRate == 0f) return;

    double omegaIn, omegaOut, warp;
    ParamField ggOutFreq;

    omegaIn = pr.para[PR_INFREQ].val / inRate * Constants.PI2;
    warp = Math.max(-0.98, Math.min(0.98, pr.para[PR_WARP].val / 100)); // DAFx2000 'b'
    omegaOut = omegaIn + 2 * Math.atan2(warp * Math.sin(omegaIn), 1.0 - warp * Math.cos(omegaIn));

    ggOutFreq = (ParamField) gui.getItemObj(GG_OUTFREQ);
    if (ggOutFreq != null) {
      ggOutFreq.setParam(new Param(omegaOut / Constants.PI2 * inRate, Param.ABS_HZ));
    }
  }
 public static void drawLine(Graphics g, int x1, int y1, int x2, int y2, int lineWidth) {
   if (lineWidth == 1) g.drawLine(x1, y1, x2, y2);
   else {
     double angle;
     double halfWidth = ((double) lineWidth) / 2.0;
     double deltaX = (double) (x2 - x1);
     double deltaY = (double) (y2 - y1);
     if (x1 == x2) angle = Math.PI;
     else angle = Math.atan(deltaY / deltaX) + Math.PI / 2;
     int xOffset = (int) (halfWidth * Math.cos(angle));
     int yOffset = (int) (halfWidth * Math.sin(angle));
     int[] xCorners = {x1 - xOffset, x2 - xOffset + 1, x2 + xOffset + 1, x1 + xOffset};
     int[] yCorners = {y1 - yOffset, y2 - yOffset, y2 + yOffset + 1, y1 + yOffset + 1};
     g.fillPolygon(xCorners, yCorners, 4);
   }
 }
Beispiel #15
0
  protected void recalcWarpAmount() {
    if (inRate == 0f) return;

    double omegaIn, omegaOut, warp, d1;
    ParamField ggWarp;

    omegaIn = pr.para[PR_INFREQ].val / inRate * Constants.PI2;
    omegaOut = pr.para[PR_OUTFREQ].val / inRate * Constants.PI2;
    d1 = Math.tan((omegaOut - omegaIn) / 2);
    warp =
        Math.max(
            -0.98,
            Math.min(0.98, d1 / (Math.sin(omegaIn) + Math.cos(omegaIn) * d1))); // DAFx2000 'b'

    ggWarp = (ParamField) gui.getItemObj(GG_WARP);
    if (ggWarp != null) {
      ggWarp.setParam(new Param(warp * 100, Param.FACTOR));
    }
  }
Beispiel #16
0
  public RandomPointset(int n) {
    // initialize
    Random generator = new Random();
    this.pointSet = new Point[n];

    // add n points to pointset
    for (int i = 0; i < n; i++) {
      double theta = 2 * Math.PI * generator.nextDouble();
      double u = generator.nextDouble() + generator.nextDouble();
      double r = 0;
      // check if point exceeds the circle
      if (u > 1) r = 2 - u;
      else r = u;
      // add the point to the pointset
      double x = r * Math.cos(theta);
      double y = r * Math.sin(theta);
      this.addPoint(x, y, i);
    }
  }
Beispiel #17
0
  /**
   * Calculate the range of a robot to the nearest wall
   *
   * @param pose the pose of the robot
   * @return the range or -1 if not in range
   */
  public float range(Pose pose) {
    Line l =
        new Line(
            pose.getX(),
            pose.getY(),
            pose.getX() + 254f * (float) Math.cos(Math.toRadians(pose.getHeading())),
            pose.getY() + 254f * (float) Math.sin(Math.toRadians(pose.getHeading())));
    Line rl = null;

    for (int i = 0; i < lines.length; i++) {
      Point p = lines[i].intersectsAt(l);
      if (p == null) continue; // Does not intersect
      Line tl = new Line(pose.getX(), pose.getY(), p.x, p.y);

      // If the range line intersects more than one map line
      // then take the shortest distance.
      if (rl == null || tl.length() < rl.length()) rl = tl;
    }
    return (rl == null ? -1 : rl.length());
  }
Beispiel #18
0
  /*======== public void addCircle() ==========
  Inputs:  int cx
           int cy
    double r
  Returns:

  Generates the edges required to make a circle and
  adds them to the EdgeMatrix.

  The circle is centered at (cx, cy) with radius r

  03/14/12 08:57:38
  jdyrlandweaver
  ====================*/
  public void addCircle(double cx, double cy, double r) {

    double x0, y0, x, y, step;

    step = 0.01;

    x0 = r + cx;
    y0 = cy;

    for (double t = step; t <= 1; t += step) {

      x = r * Math.cos(2 * Math.PI * t) + cx;
      y = r * Math.sin(2 * Math.PI * t) + cy;

      addEdge(x0, y0, 0, x, y, 0);
      x0 = x;
      y0 = y;
    }

    addEdge(x0, y0, 0, r + cx, cy, 0);
  }
Beispiel #19
0
  public void method353(int i, double d, int l1) {
    // all of the following were parameters
    int j = 15;
    int k = 20;
    int l = 15;
    int j1 = 256;
    int k1 = 20;
    // all of the previous were parameters
    try {
      int i2 = -k / 2;
      int j2 = -k1 / 2;
      int k2 = (int) (Math.sin(d) * 65536D);
      int l2 = (int) (Math.cos(d) * 65536D);
      k2 = k2 * j1 >> 8;
      l2 = l2 * j1 >> 8;
      int i3 = (l << 16) + (j2 * k2 + i2 * l2);
      int j3 = (j << 16) + (j2 * l2 - i2 * k2);
      int k3 = l1 + i * DrawingArea.width;
      for (i = 0; i < k1; i++) {
        int l3 = k3;
        int i4 = i3;
        int j4 = j3;
        for (l1 = -k; l1 < 0; l1++) {
          int k4 = myPixels[(i4 >> 16) + (j4 >> 16) * myWidth];
          if (k4 != 0) DrawingArea.pixels[l3++] = k4;
          else l3++;
          i4 += l2;
          j4 -= k2;
        }

        i3 += k2;
        j3 += l2;
        k3 += DrawingArea.width;
      }

    } catch (Exception _ex) {
    }
  }
Beispiel #20
0
  private void spawnCircles() {
    if (circular) {
      for (int i = 0; i < ballN; i++) {
        double degree = Math.random() * 2 * Math.PI;
        float x = ((Player) players.get(0)).getX() + distance * (float) Math.sin(degree * i);
        float y = ((Player) players.get(0)).getY() + distance * (float) Math.cos(degree * i);
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }
    } else {
      for (int i = 1; i < (ballN / 2); i++) {
        float x = (i * 2 * width) / (ballN);
        float y = 0;
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }

      for (int i = (ballN / 2) + 1; i < ballN; i++) {
        float x = ((i - ballN / 2) * 2 * width) / ballN;
        float y = height;
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }
    }
    spawnIncrease = false;
  }
Beispiel #21
0
  /** Rotate theta degrees around the y axis */
  void yrot(double theta) {
    theta *= (pi / 180);
    double ct = Math.cos(theta);
    double st = Math.sin(theta);

    double Nxx = (xx * ct + zx * st);
    double Nxy = (xy * ct + zy * st);
    double Nxz = (xz * ct + zz * st);
    double Nxo = (xo * ct + zo * st);

    double Nzx = (zx * ct - xx * st);
    double Nzy = (zy * ct - xy * st);
    double Nzz = (zz * ct - xz * st);
    double Nzo = (zo * ct - xo * st);

    xo = Nxo;
    xx = Nxx;
    xy = Nxy;
    xz = Nxz;
    zo = Nzo;
    zx = Nzx;
    zy = Nzy;
    zz = Nzz;
  }
Beispiel #22
0
  /** Rotate theta degrees about the x axis */
  void xrot(double theta) {
    theta *= (pi / 180);
    double ct = Math.cos(theta);
    double st = Math.sin(theta);

    double Nyx = (yx * ct + zx * st);
    double Nyy = (yy * ct + zy * st);
    double Nyz = (yz * ct + zz * st);
    double Nyo = (yo * ct + zo * st);

    double Nzx = (zx * ct - yx * st);
    double Nzy = (zy * ct - yy * st);
    double Nzz = (zz * ct - yz * st);
    double Nzo = (zo * ct - yo * st);

    yo = Nyo;
    yx = Nyx;
    yy = Nyy;
    yz = Nyz;
    zo = Nzo;
    zx = Nzx;
    zy = Nzy;
    zz = Nzz;
  }
Beispiel #23
0
  /** Rotate theta degrees about the z axis */
  void zrot(double theta) {
    theta *= pi / 180;
    double ct = Math.cos(theta);
    double st = Math.sin(theta);

    double Nyx = (yx * ct + xx * st);
    double Nyy = (yy * ct + xy * st);
    double Nyz = (yz * ct + xz * st);
    double Nyo = (yo * ct + xo * st);

    double Nxx = (xx * ct - yx * st);
    double Nxy = (xy * ct - yy * st);
    double Nxz = (xz * ct - yz * st);
    double Nxo = (xo * ct - yo * st);

    yo = Nyo;
    yx = Nyx;
    yy = Nyy;
    yz = Nyz;
    xo = Nxo;
    xx = Nxx;
    xy = Nxy;
    xz = Nxz;
  }
 public double dervActivation(double x) {
   // return derv(activation(x));
   return (1 / Math.pow(Math.cos(x), 2));
 }
Beispiel #25
0
 private int yCor(int len, double dir) {
   return (int) (len * Math.cos(dir));
 }
Beispiel #26
0
 private int polar_to_rect_x(int rad, int angle) {
   return (int) Math.round(rad * Math.cos((double) angle * Math.PI / 180.0));
 }
  @Override
  public void actionPerformed(ActionEvent e) {

    double SinTOA, SinTOA_value, I0, Rm, R, eta, delta, omega, etarad, deltarad, omegarad;
    int Year, Month;
    // double trans_Value, albedo_value;
    int FID;

    FileDialog fd =
        new FileDialog(new Frame(), "Open radiation data .txt/.csv file", FileDialog.LOAD);
    fd.setVisible(true);
    File f = new File(fd.getDirectory() + fd.getFile());

    System.out.println("File opened");

    FileReader fr = null;

    ArrayList<Double> SinTOA_list = new ArrayList<Double>();
    ArrayList<Integer> FID_list = new ArrayList<Integer>();
    ArrayList<Double> delta_list = new ArrayList<Double>();
    ArrayList<Double> omega_list = new ArrayList<Double>();
    ArrayList<Integer> year_list = new ArrayList<Integer>();
    ArrayList<Integer> month_list = new ArrayList<Integer>();
    // ArrayList <Double> trans_Value_list = new ArrayList<Double>();
    // ArrayList <Double> albedo_value_list = new ArrayList<Double>();

    try {

      fr = new FileReader(f);

    } catch (FileNotFoundException fnfe) {
    }

    BufferedReader br = new BufferedReader(fr);

    I0 = 1368; // Watts m^-2
    Rm = 1;
    R = Rm;
    eta = 68.35; // deg latitude
    // BufferedReader br = null;
    // BufferedWriter bw = null;

    try {

      String line;

      br.readLine(); // Skips first line in file (useful if you have a header)

      while ((line = br.readLine()) != null) {
        // System.out.println(line);

        StringTokenizer stringTokenizer = new StringTokenizer(line, ",");

        while (stringTokenizer.hasMoreElements()) {

          FID = Integer.parseInt(stringTokenizer.nextElement().toString());
          System.out.println("FID = " + FID);
          Year = Integer.parseInt(stringTokenizer.nextElement().toString());
          System.out.println("Year = " + Year);
          Month = Integer.parseInt(stringTokenizer.nextElement().toString());
          System.out.println("Month = " + Month);
          delta = Double.parseDouble(stringTokenizer.nextElement().toString());
          System.out.println("delta = " + delta);
          omega = Double.parseDouble(stringTokenizer.nextElement().toString());
          System.out.println("omega = " + omega);
          // System.out.println("delta = " + delta);
          // System.out.println("omega = " + omega);

          // *******************************************************************************

          // **************************** Sin_TOA CALCULATION
          etarad = Math.toRadians(eta); // Convert to radians
          deltarad = Math.toRadians(delta); // Convert to radians
          omegarad = Math.toRadians(omega); // Convert to radians

          double cossin_calc =
              ((Math.cos(etarad) * Math.cos(deltarad) * Math.cos(omegarad))
                  + (Math.sin(etarad) * Math.sin(deltarad)));

          double cossin_calc_deg = cossin_calc / 0.0174532925;

          SinTOA = I0 * ((Rm / R) * (Rm / R)) * cossin_calc_deg;

          if (SinTOA >= 0) {
            SinTOA_value = SinTOA;
          } else {
            SinTOA_value = 0;
          }
          // **************** Array List *************************
          SinTOA_list.add(SinTOA_value);
          FID_list.add(FID);
          delta_list.add(delta);
          omega_list.add(omega);
          year_list.add(Year);
          month_list.add(Month);

          // **************** Array List *************************
          // SinTOA_list.add(SinTOA);
          // System.out.println("SinTOA array list created");
          // **************** Array List *************************

          // **************************** Sin_TOA CALCULATION

          // ************************** Mock transmissivity and albedo value
          // trans_Value = 0.48 * SinTOA_value; // tau is set as 0.48 here just as a test
          // albedo_value = trans_Value * 0.5;

          // **************** Array List *************************
          // trans_Value_list.add(trans_Value);
          // System.out.println("Trans value array list created");
          // albedo_value_list.add(albedo_value);
          // System.out.println("Albedo array list created");
          // **************** Array List *************************

          // ************************** Mock transmissivity and albedo value

          //                         System.out.println("FID = " +FID);
          //                         if(SinTOA > 0){
          //                                System.out.println("TOA = " + SinTOA);
          //                                System.out.println("Transmissivity adjustment = " +
          // trans_Value);
          //                                System.out.println("Albedo adjustment: " +
          // albedo_value);
          //                                //System.out.println("Must be sunny! Is it summmer?");
          //                         } else{
          //                                System.out.println("TOA = " + "No incoming solar
          // energy");
          //                                //System.out.println("Brrrrrr, no sun? Is it winter or
          // night?");
          //                         }

          // **************** Array List Test*************************
          //                         int SinTOASize = SinTOA_list.size();
          //                         int transSize = trans_Value_list.size();
          //                         int albedoSize = albedo_value_list.size();
          //
          //                         System.out.println("SinTOA list length: " + SinTOASize);
          //                         System.out.println("Trans list length: " + transSize);
          //                         System.out.println("Albedo list length: " + albedoSize);
          // **************** Array List Test*************************
        }
      }

      //                         int SinTOASize = SinTOA_list.size();
      //                         int transSize = trans_Value_list.size();
      //                         int albedoSize = albedo_value_list.size();

      //                         System.out.println("SinTOA list length: " + SinTOASize);
      //                         System.out.println("Trans list length: " + transSize);
      //                         System.out.println("Albedo list length: " + albedoSize);

    } catch (IOException ex) {
    }

    // *****************************FILE WRITING ROUTINE********************************************
    // File f2 = new File("F:/Melt_modelling/Model_outputs/TOA_test.txt");

    FileDialog fd2 = new FileDialog(new Frame(), "Save TOA Radiation file", FileDialog.SAVE);
    fd2.setVisible(true);

    File f2 = new File(fd2.getDirectory() + fd2.getFile());

    FileWriter fw = null;
    ArrayList<Double> output = new ArrayList<Double>();
    // output = SinTOA_list;

    try {

      fw = new FileWriter(f2, true);

    } catch (IOException ioe) {

      ioe.printStackTrace();
    }

    BufferedWriter bw = new BufferedWriter(fw);

    try {

      bw.write(
          "FID, Year, Month, Delta (Declination), Omega (solar hour), Sin TOA (Wm^-2)"); // , Tau
      // corrected Sin TOA (Wm^-2), Albedo mod. of tau correction (Wm^-2)");
      bw.newLine();

      //      delta_list.add(delta);
      //      omega_list.add(omega);

      Iterator<Double> iterator1 = SinTOA_list.iterator();
      //      Iterator<Double> iterator2 = trans_Value_list.iterator();
      //      Iterator<Double> iterator3 = albedo_value_list.iterator();
      Iterator<Integer> iterator2 = year_list.iterator();
      Iterator<Integer> iterator3 = month_list.iterator();
      Iterator<Integer> iterator4 = FID_list.iterator();
      Iterator<Double> iterator5 = delta_list.iterator();
      Iterator<Double> iterator6 = omega_list.iterator();
      // while ((iterator1.hasNext())&&(iterator2.hasNext())&&(iterator3.hasNext())) {
      while (iterator1.hasNext() && iterator4.hasNext()) {
        //			System.out.println(iterator1.next());
        //                        System.out.println(iterator2.next());
        //                        System.out.println(iterator3.next());

        String FID_print = Integer.toString(iterator4.next());
        String delta_print = Double.toString(iterator5.next());
        String omega_print = Double.toString(iterator6.next());
        String SinTOA_print = Double.toString(iterator1.next());
        String month_print = Integer.toString(iterator3.next());
        String year_print = Integer.toString(iterator2.next());

        //                        String tau_print = Double.toString(iterator2.next());
        //                        String albedo_print = Double.toString(iterator3.next());

        bw.write(FID_print);
        bw.write(",");
        bw.write(year_print);
        bw.write(",");
        bw.write(month_print);
        bw.write(",");
        bw.write(delta_print);
        bw.write(",");
        bw.write(omega_print);
        bw.write(",");
        bw.write(SinTOA_print);
        //                        bw.write(",");
        //                        bw.write(tau_print);
        //                        bw.write(",");
        //                        bw.write(albedo_print);
        bw.newLine();
      }

      bw.close();
      fw.close();

    } catch (IOException ioe) {
      System.out.println(ioe.toString());
    }

    // *****************************FILE WRITING ROUTINE********************************************

    finally {
      try {
        if (br != null) br.close();

      } catch (IOException ex) {
      }
    }

    // System.out.println("File written");

    System.out.println("Model run successful");
  }
Beispiel #28
0
  private int[] Translated_Point(double constant, int[] arrow_x, int[] arrow_y, double gradient) {
    double[] translated = new double[2];
    double[][] trans_matrix = new double[2][2];
    double ang_rot;
    double[] point2_temp = new double[4];
    int cnt, row, col;
    int[] pt = new int[2];

    translated[0] = 0.00;
    translated[1] = 0.00;
    trans_matrix[0][0] = 0.00;
    trans_matrix[0][1] = 0.00;
    trans_matrix[1][0] = 0.00;
    trans_matrix[1][1] = 0.00;
    point2_temp[0] = 0.00;
    point2_temp[1] = 0.00;
    point2_temp[2] = 0.00;
    point2_temp[3] = 0.00;
    cnt = 0;
    row = 0;
    col = 0;
    ang_rot = 0.00;

    // translate the line to the origin
    // thus the translated points to be found are:
    translated[0] = arrow_x[1];
    if (constant < 0) {
      translated[1] = arrow_y[1] + Math.abs(constant);
    } else {
      translated[1] = arrow_y[1] - Math.abs(constant);
    }

    // find the angle of rotation
    ang_rot = Math.atan(gradient);

    if ((end_x - start_x) == 0) {
      if (arrow_x[0] > 0) {
        translated[0] = arrow_x[1] - arrow_x[0];
      } else {
        translated[0] = arrow_x[1] + arrow_x[0];
      }
      translated[1] = arrow_y[1];
      trans_matrix[0][0] = -1;
      trans_matrix[0][1] = 0;
      trans_matrix[1][0] = 0;
      trans_matrix[1][1] = 1;
    } else {
      // declare the transformation matrix
      trans_matrix[0][0] = Math.cos(2 * ang_rot);
      trans_matrix[0][1] = Math.sin(2 * ang_rot);
      trans_matrix[1][0] = Math.sin(2 * ang_rot);
      trans_matrix[1][1] = Math.cos(2 * ang_rot) * (-1);
    }

    // multiply the transformation matrix with the point
    // store it in an array
    for (row = 0; row < 2; row++) {
      for (col = 0; col < 2; col++) {
        point2_temp[cnt] = trans_matrix[row][col] * translated[col];
        cnt++;
      }
    }

    if ((end_x - start_x) == 0) {
      if (arrow_x[0] > 0) {
        arrow_x[2] = (int) Math.round(point2_temp[0] + point2_temp[1] + arrow_x[0]);
      } else {
        arrow_x[2] = (int) Math.round(point2_temp[2] + point2_temp[1] - arrow_x[0]);
      }
      arrow_y[2] = (int) Math.round(point2_temp[2] + point2_temp[3]);
    } else {
      // from the array, get the reflected point
      arrow_x[2] = (int) Math.round(point2_temp[0] + point2_temp[1]);
      if (constant < 0) {
        arrow_y[2] = (int) Math.round(point2_temp[2] + point2_temp[3] - Math.abs(constant));
      } else {
        arrow_y[2] = (int) Math.round(point2_temp[2] + point2_temp[3] + Math.abs(constant));
      }
    }
    pt[0] = arrow_x[2];
    pt[1] = arrow_y[2];
    return pt;
  }
 public void move() {
   objtimer++;
   // move
   if (xmot.random && objtimer % (int) (35 * xmot.randomchg) == 0) {
     xspeed = xmot.speed * random(-1, 1, 2);
   }
   if (ymot.random && objtimer % (int) (35 * ymot.randomchg) == 0) {
     yspeed = ymot.speed * random(-1, 1, 2);
   }
   if (player != null) {
     double playerdist =
         Math.sqrt((player.x - x) * (player.x - x) + (player.y - y) * (player.y - y))
             * 100.0
             / (pfWidth());
     if (xmot.toplayer && playerdist > xmot.toplayermin && playerdist < xmot.toplayermax) {
       xspeed = 0;
       x += xmot.speed * (player.x > x ? 1 : -1);
     } else if (xmot.frplayer
         && playerdist > xmot.frplayermin
         && playerdist < xmot.frplayermax) {
       xspeed = 0;
       x += xmot.speed * (player.x < x ? 1 : -1);
     }
     if (ymot.toplayer && playerdist > ymot.toplayermin && playerdist < ymot.toplayermax) {
       yspeed = 0;
       y += ymot.speed * (player.y > y ? 1 : -1);
     } else if (ymot.frplayer
         && playerdist > ymot.frplayermin
         && playerdist < ymot.frplayermax) {
       yspeed = 0;
       y += ymot.speed * (player.y < y ? 1 : -1);
     }
   }
   // react to background
   int bounces = 0;
   if (bouncesides.equals("any")) {
     bounces |= 15;
   } else if (bouncesides.equals("top")) {
     bounces |= 1;
   } else if (bouncesides.equals("bottom")) {
     bounces |= 2;
   } else if (bouncesides.equals("topbottom")) {
     bounces |= 3;
   } else if (bouncesides.equals("left")) {
     bounces |= 4;
   } else if (bouncesides.equals("right")) {
     bounces |= 8;
   } else if (bouncesides.equals("leftright")) {
     bounces |= 12;
   }
   if ((bounces & 1) != 0 && y < 0) {
     y = 0;
     if (yspeed < 0) yspeed = -yspeed;
   }
   if ((bounces & 2) != 0 && y > pfHeight() - 16) {
     y = pfHeight() - 16;
     if (yspeed > 0) yspeed = -yspeed;
   }
   if ((bounces & 4) != 0 && x < 0) {
     x = 0;
     if (xspeed < 0) xspeed = -xspeed;
   }
   if ((bounces & 8) != 0 && x > pfWidth() - 16) {
     x = pfWidth() - 16;
     if (xspeed > 0) xspeed = -xspeed;
   }
   // shoot
   if (shoot && shootfreq > 0.0 && objtimer % (int) (shootfreq * 35) == 0) {
     if (shootdir.equals("left")) {
       new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, -shootspeed, 0);
     } else if (shootdir.equals("right")) {
       new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, shootspeed, 0);
     } else if (shootdir.equals("up")) {
       new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, 0, -shootspeed);
     } else if (shootdir.equals("down")) {
       new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, 0, shootspeed);
     } else if (shootdir.equals("player") && player != null) {
       double angle = Math.atan2(player.x - x, player.y - y);
       new AgentBullet(
           x,
           y,
           bullettype,
           sprite,
           diebgtype | blockbgtype,
           shootspeed * Math.sin(angle),
           shootspeed * Math.cos(angle));
     }
   }
 }
Beispiel #30
0
  public void Draw_Arrow(Graphics g) {
    double arrow_angle;
    int[] arrow_x = new int[3];
    int[] arrow_y = new int[3];
    int[] arrow_pt = new int[2];
    double gradient, constant;
    double distance, temp_dist;
    double mid_x_diff, mid_y_diff;
    double arrow_ratio;
    double trans_pts_x, trans_pts_y;

    trans_pts_x = 0.00;
    trans_pts_y = 0.00;
    arrow_ratio = 0.00;
    mid_x_diff = 0.00;
    mid_y_diff = 0.00;
    distance = 0.00;
    temp_dist = 0.00;
    gradient = 0.00;
    constant = 0.00;
    arrow_x[0] = 0;
    arrow_x[1] = 0;
    arrow_x[2] = 0;
    arrow_y[0] = 0;
    arrow_y[1] = 0;
    arrow_y[2] = 0;
    arrow_angle = 0.00;

    arrow_angle = (start_angle + arc_angle / 2) * Math.PI / 180;
    //		if (num_arcs != 1) {
    arrow_x[0] = (int) Math.round(img_mid_x + img_cir * Math.cos(arrow_angle));
    arrow_y[0] = (int) Math.round(img_mid_y - img_cir * Math.sin(arrow_angle));
    //			}
    //		else {
    //			arrow_x[0] = mid_pt_x;
    //			arrow_y[0] = mid_pt_y;
    //			g.drawString("1", (int)arrow_x[0], (int)arrow_y[0]);
    //		}
    /*calculate the distance between the midpt (on arc) and start node*/
    mid_x_diff = Math.abs(arrow_x[0] - start_x);
    mid_y_diff = Math.abs(arrow_y[0] - start_y);

    distance = Math.sqrt((mid_x_diff * mid_x_diff) + (mid_y_diff * mid_y_diff));

    temp_dist = distance - HEAD_DISTANCE;
    arrow_ratio = temp_dist / distance;
    arrow_x[1] = (int) ((arrow_x[0] - start_x) * arrow_ratio + start_x);
    arrow_y[1] = (int) ((arrow_y[0] - start_y) * arrow_ratio + start_y);

    // calculate the gradient of the tangent
    // equation of the circle is (x-c)^2 + (y-d)^2 = R^2
    // equation of the line is y = mx + c
    gradient = ((-1) * (arrow_x[0] - img_mid_x)) / (arrow_y[0] - img_mid_y);
    // find the constant value of the line
    constant = arrow_y[0] - gradient * arrow_x[0];

    arrow_pt = Translated_Point(constant, arrow_x, arrow_y, gradient);
    arrow_x[2] = arrow_pt[0];
    arrow_y[2] = arrow_pt[1];

    if (num_arcs == 1 && testcase != 10) {
      /*x and y distances between mid pts and arc mid pts */
      trans_pts_x = arrow_x[0] - mid_pt_x;
      trans_pts_y = arrow_y[0] - mid_pt_y;
      arrow_x[0] = mid_pt_x;
      arrow_y[0] = mid_pt_y;
      arrow_x[1] = arrow_x[1] - (int) trans_pts_x;
      arrow_y[1] = arrow_y[1] - (int) trans_pts_y;
      arrow_x[2] = arrow_x[2] - (int) trans_pts_x;
      arrow_y[2] = arrow_y[2] - (int) trans_pts_y;
    } else if (num_arcs == 1 && testcase == 10) {
      System.out.println("hello...");
      arrow_x[0] = (int) (start_x - diameter);
      arrow_y[0] = (int) start_y;
      arrow_x[1] = (int) (diameter / 4 + arrow_x[0]);
      arrow_y[1] = (int) (diameter / 6 - arrow_y[0]);
      arrow_x[2] = (int) (diameter / 4 - arrow_x[0]);
      arrow_y[2] = (int) (diameter / 6 - arrow_y[0]);
    }
    g.setColor(arrow_colour);
    g.fillPolygon(arrow_x, arrow_y, 3);
    if (value != 0) {
      g.setColor(value_colour);
      if (show_cost) {
        Display_Value(g, arrow_x, arrow_y);
      }
    }
  }