/**
  * Write the given text string in the current font, centered on (x, y) and rotated by the
  * specified number of degrees
  *
  * @param x the center x-coordinate of the text
  * @param y the center y-coordinate of the text
  * @param s the text
  * @param degrees is the number of degrees to rotate counterclockwise
  */
 public static void text(double x, double y, String s, double degrees) {
   double xs = scaleX(x);
   double ys = scaleY(y);
   offscreen.rotate(Math.toRadians(-degrees), xs, ys);
   text(x, y, s);
   offscreen.rotate(Math.toRadians(+degrees), xs, ys);
 }
 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);
 }
  /* 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);
    }
  }
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y), rotated given number of degrees
   *
   * @param x the center x-coordinate of the image
   * @param y the center y-coordinate of the image
   * @param s the name of the image/picture, e.g., "ball.gif"
   * @param degrees is the number of degrees to rotate counterclockwise
   * @throws RuntimeException if the image is corrupt
   */
  public static void picture(double x, double y, String s, double degrees) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    int ws = image.getWidth(null);
    int hs = image.getHeight(null);
    if (ws < 0 || hs < 0) throw new RuntimeException("image " + s + " is corrupt");

    offscreen.rotate(Math.toRadians(-degrees), xs, ys);
    offscreen.drawImage(
        image, (int) Math.round(xs - ws / 2.0), (int) Math.round(ys - hs / 2.0), null);
    offscreen.rotate(Math.toRadians(+degrees), xs, ys);

    draw();
  }
Example #5
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());
  }
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y), rotated given number of degrees, rescaled
   * to w-by-h.
   *
   * @param x the center x-coordinate of the image
   * @param y the center y-coordinate of the image
   * @param s the name of the image/picture, e.g., "ball.gif"
   * @param w the width of the image
   * @param h the height of the image
   * @param degrees is the number of degrees to rotate counterclockwise
   * @throws RuntimeException if the image is corrupt
   */
  public static void picture(double x, double y, String s, double w, double h, double degrees) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    double ws = factorX(w);
    double hs = factorY(h);
    if (ws < 0 || hs < 0) throw new RuntimeException("image " + s + " is corrupt");
    if (ws <= 1 && hs <= 1) pixel(x, y);

    offscreen.rotate(Math.toRadians(-degrees), xs, ys);
    offscreen.drawImage(
        image,
        (int) Math.round(xs - ws / 2.0),
        (int) Math.round(ys - hs / 2.0),
        (int) Math.round(ws),
        (int) Math.round(hs),
        null);
    offscreen.rotate(Math.toRadians(+degrees), xs, ys);

    draw();
  }
  @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");
  }
Example #8
0
 /**
  * Returns the text rotation in radians : subclassers that don't support rotating text may return
  * 0 here. Used by TextLayout only.
  */
 protected double getRotation() {
   //			debug(set.getAttribute(TEXT_ROTATION).toString());
   return Math.toRadians(element.getAttribute(TEXT_ROTATION).doubleValue());
 }
Example #9
0
 public static void main(String[] args) {
   double deg = 30;
   double rad = Math.toRadians(deg);
   double ans = Math.atan(rad);
   System.out.println(ans);
 }
Example #10
0
  // Convert from Degrees to Radians.
  private float AR_DegToRad(float x) {

    return (float) Math.toRadians(x);
  }