Пример #1
0
 public void drawOrbits(ArrayList alObjectsArchive) {
   //  println("SIZE:" + alObjectsArchive.size());
   //  ArrayList alObjectsArchive = timeline.getObjectStateArchive();
   ArrayList alPrevPos = new ArrayList();
   ArrayList alColors = new ArrayList();
   alColors.add(color(255, 0, 0));
   alColors.add(color(255, 255, 0));
   alColors.add(color(255, 0, 255));
   //  for (int i = timeline.getTimeIdx(); i >= 0 && i > (timeline.getTimeIdx() - 1 - 100); i--)
   for (int i = 0; i < alObjectsArchive.size(); i++) {
     ArrayList objects = (ArrayList) alObjectsArchive.get(i);
     for (int j = 0; j < objects.size(); j++) {
       CelestialObject obj = (CelestialObject) objects.get(j);
       //      CelestialObject obj = (CelestialObject)objects.get(1);
       PVector pos = obj.getPosition();
       //      stroke(0, 0, 255);
       stroke((Integer) alColors.get(j));
       if (alPrevPos.size() == objects.size()) {
         PVector prevPos = (PVector) alPrevPos.get(j);
         line(prevPos.x, prevPos.y, pos.x, pos.y);
         alPrevPos.set(j, pos);
       } else alPrevPos.add(pos);
     }
   }
 }
Пример #2
0
 public void mouseClicked() {
   ArrayList objects = timeline.getStatefulObjects();
   for (int i = 0; i < objects.size(); i++) {
     CelestialObject obj = (CelestialObject) objects.get(i);
     if (obj.isMouseOver()) {
       println(obj.getName() + " clicked!");
       break;
     }
   }
 }
Пример #3
0
    public CelestialObject clone() {
      try {
        CelestialObject obj = (CelestialObject) super.clone();

        obj.position = new PVector(obj.position.x, obj.position.y);
        obj.velocity = new PVector(obj.velocity.x, obj.velocity.y);
        obj.acceleration = new PVector(obj.acceleration.x, obj.acceleration.y);
        obj.alForces = cloneArrayList(obj.alForces);

        return obj;
      } catch (final CloneNotSupportedException ex) {
        throw new AssertionError();
      }
    }
Пример #4
0
  public void draw() {
    background(0);
    fill(255);

    if (!paused) timeline.moveForward();

    if (dragging) drawOrbits(timeline.getFutureObjectStates());
    else drawOrbits(timeline.getPastObjectStates());

    ArrayList objects = timeline.getStatefulObjects();
    for (int i = 0; i < objects.size(); i++) {
      CelestialObject obj = (CelestialObject) objects.get(i);
      obj.display();
    }
  }
Пример #5
0
  public void mouseDragged() {
    if (paused) {
      ArrayList objects = timeline.getStatefulObjects();
      for (int i = 0; i < objects.size(); i++) {
        CelestialObject obj = (CelestialObject) objects.get(i);
        if (obj.isMouseOver()) {
          dragging = true;
          PVector pos = obj.getPosition();
          pos.x = mouseX;
          pos.y = mouseY;

          timeline.reset();
          timeline.setCurrentState(objects);
          sliderTimeline.setValue(0);
          break;
        }
      }
    }
  }
Пример #6
0
  /**
   * Search all the stars that has all the condition of the string
   *
   * @param _searchText The string that will be analyze by the function decryptText
   * @param _date It's the date that will be use to search the stars
   * @param _dLat It's the latitude of the star's pointer
   * @param _dLon It's the longitude of the star's pointer
   * @throws SQLException
   * @return Return an arraylist of CelestialObject.
   */
  public ArrayList<CelestialObject> starsForText(
      String _searchText, Calendar _date, double _dLat, double _dLon) throws SQLException {
    ArrayList<CelestialObject> al_stars = new ArrayList<CelestialObject>();

    int l_id;
    int l_HIP;
    int l_HD;
    int l_HR;
    String l_ProperName;
    double l_dRA;
    double l_Dec;
    double l_dDistance;
    double l_dMag;
    double l_dColorIndex;

    boolean secured = false;

    HashMap<String, String> hm_sWhere = decryptText(_searchText);
    Iterator<String> l_it = hm_sWhere.keySet().iterator();

    String[] table = {this.sTable};
    String[] field = {"*"};
    String[][] where = new String[hm_sWhere.size()][3];
    String[] orderby = {"id"};
    int[] limit = {};
    secured = true;

    int i = 0;

    while (l_it.hasNext()) {
      String l_sTemp = l_it.next().toString();
      where[i][0] = l_sTemp;
      where[i][1] = "LIKE";
      where[i][2] = "%" + hm_sWhere.get(l_sTemp).toString().trim() + "%";
      i++;
    }

    ResultSet result = selectQuery(field, table, where, orderby, limit, secured);

    try {
      if (!isDouble(Double.toString(_dLon)) || !isDouble(Double.toString(_dLat)))
        throw new IllegalArgumentException(
            "Error : Illegal latitude/longitude. Please check the coordinates !");
    } catch (IllegalArgumentException e) {
      log.warning(e.getMessage());
      _dLat = _dLon = 0;
    }

    Mathematics l_calc = new Mathematics(_date, _dLat, _dLon);

    try {
      while (result.next()) {
        int l_Bayer = 0;
        l_id = result.getInt("id");
        l_HIP = result.getInt("HIP");
        l_HD = result.getInt("HD");
        l_HR = result.getInt("HR");
        l_ProperName = result.getString("ProperName");
        l_dRA = result.getDouble("RA");
        l_Dec = result.getDouble("Dec");
        l_dDistance = result.getDouble("Distance");
        l_dMag = result.getDouble("Mag");
        l_dColorIndex = result.getDouble("ColorIndex");

        CelestialObject l_star =
            new CelestialObject(
                l_id,
                l_HIP,
                l_HD,
                l_HR,
                l_ProperName,
                l_dRA,
                l_Dec,
                l_dDistance,
                l_dMag,
                l_dColorIndex,
                l_Bayer);

        if (l_id == 1) {
          l_calc.calculatePositionSun();
          l_star.setDec(l_calc.getDeclination());
          l_star.setRA(l_calc.getAscension());
        } else if (l_id == 2) {
          l_calc.calculatePositionMoon();
          l_star.setDec(l_calc.getDeclination());
          l_star.setRA(l_calc.getAscension());
          double l_now = l_calc.getMoonBrightness(false);
          double l_yes = l_calc.getMoonBrightness(true);
          if (l_yes > l_now) l_now *= -1;

          l_star.setMag(l_now);
        } else l_calc.calculateAll(l_star.getDec(), l_star.getRA());

        if (l_calc.getHeight() > 0) {
          l_star.setXReal(l_calc.getX());
          l_star.setYReal(l_calc.getY());
          l_star.SetAzimuth(l_calc.getAzimuth());
          l_star.SetHeight(l_calc.getHeight());
          al_stars.add(l_star);
        }

        l_star = null;
      }
    } catch (SQLException e) {
      log.warning("Problem with the query's result !");
    }
    result.close();
    return al_stars;
  }
Пример #7
0
  /**
   * Search all the stars that could be in the hemisphere
   *
   * @param _date It's the date that will be use to search the stars
   * @param _dLat It's the latitude of the star's pointer
   * @param _dLon It's the longitude of the star's pointer
   * @throws SQLException
   * @return Return an arraylist that contains all the stars could be possible to see
   */
  public ArrayList<CelestialObject> starsForCoordinates(Calendar _date, double _dLat, double _dLon)
      throws SQLException {
    ArrayList<CelestialObject> al_stars = new ArrayList<CelestialObject>();

    int l_Bayer = 0;
    int l_id;
    int l_HIP;
    int l_HD;
    int l_HR;
    String l_ProperName;
    double l_dRA;
    double l_Dec;
    double l_dDistance;
    double l_dMag;
    double l_dColorIndex;

    try {
      if (!isDouble(Double.toString(_dLon)) || !isDouble(Double.toString(_dLat)))
        throw new IllegalArgumentException(
            "Error : Illegal latitude/longitude. Please check the coordinates !");
    } catch (IllegalArgumentException e) {
      log.warning(e.getMessage());
      _dLat = _dLon = 0;
    }

    Mathematics l_calc = new Mathematics(_date, _dLat, _dLon);

    for (CelestialObject star : this.allStars) {
      l_id = star.getId();
      l_HIP = star.getHIP();
      l_HD = star.getHD();
      l_HR = star.getHR();
      l_ProperName = star.getProperName();
      l_dRA = star.getRA();
      l_Dec = star.getDec();
      l_dDistance = star.getDistance();
      l_dMag = star.getMag();
      l_dColorIndex = star.getColorIndex();

      CelestialObject l_star =
          new CelestialObject(
              l_id,
              l_HIP,
              l_HD,
              l_HR,
              l_ProperName,
              l_dRA,
              l_Dec,
              l_dDistance,
              l_dMag,
              l_dColorIndex,
              l_Bayer);

      if (l_id == 1) // Sun
      {
        l_calc.calculatePositionSun();
        l_star.setDec(l_calc.getDeclination());
        l_star.setRA(l_calc.getAscension());
      } else if (l_id == 2) // Moon
      {
        l_calc.calculatePositionMoon();
        l_star.setDec(l_calc.getDeclination());
        l_star.setRA(l_calc.getAscension());
        double l_now = l_calc.getMoonBrightness(false);
        double l_yes = l_calc.getMoonBrightness(true);
        if (l_yes > l_now) l_now *= -1;

        l_star.setMag(l_now);
      } else l_calc.calculateAll(l_star.getDec(), l_star.getRA());

      if (l_calc.getHeight() >= 0) {
        l_star.setXReal(l_calc.getX());
        l_star.setYReal(l_calc.getY());
        l_star.SetAzimuth(l_calc.getAzimuth());
        l_star.SetHeight(l_calc.getHeight());
        al_stars.add(l_star);
      }

      l_star = null;
    }

    return al_stars;
  }
Пример #8
0
  /**
   * Search all the constellations that could be in the hemisphere
   *
   * @param _date It's the date that will be use to search the stars
   * @param _dLat It's the latitude of the star's pointer
   * @param _dLon It's the longitude of the star's pointer
   * @throws SQLException
   * @return Return an arraylist that contains all the constellations could be possible to see
   */
  public ArrayList<Constellation> getConstellations(Calendar _date, double _dLat, double _dLon) {
    ArrayList<Constellation> al_const = new ArrayList<Constellation>();

    String l_ProperName;
    String l_oldProperName = "";
    double l_dRA;
    double l_Dec;

    int l_Id;

    double l_X = 0.0;
    double l_Y = 0.0;
    double l_Xp = 0.0;
    double l_Yp = 0.0;
    boolean l_bStop = false;

    int i = 0;
    try {
      if (!isDouble(Double.toString(_dLon)) || !isDouble(Double.toString(_dLat)))
        throw new IllegalArgumentException(
            "Error : Illegal latitude/longitude. Please check the coordinates !");
    } catch (IllegalArgumentException e) {
      log.warning(e.getMessage());
      _dLat = _dLon = 0;
    }

    Mathematics l_calc = new Mathematics(_date, _dLat, _dLon);
    Constellation l_consts = new Constellation();

    for (CelestialObject l_const : this.allConstellations) {
      l_ProperName = Messages.getString("MainView.Const_" + l_const.getProperName());
      l_dRA = l_const.getRA();
      l_Dec = l_const.getDec();
      l_Id = l_const.getId();

      if (!l_ProperName.equals(l_oldProperName)) l_bStop = false;

      if (!l_bStop) {
        if (!l_ProperName.equals(l_oldProperName) && !l_oldProperName.equals("")) {
          if (i != 0) {
            l_consts.setNameCoordinates();
            al_const.add(l_consts);
          }
          l_consts = null;
          if (l_Id == 0) break;
          l_consts = new Constellation();
          i = 0;
        }

        if (i++ == 0) l_consts.setProperName(l_ProperName);

        l_calc.calculateAll(l_Dec, l_dRA);

        if (l_calc.getHeight() >= 0) {
          l_X = l_calc.getX();
          l_Y = l_calc.getY();

          if (l_ProperName.equals(l_oldProperName) && i % 2 == 0)
            l_consts.addLine(l_Xp, -l_Yp, l_X, -l_Y);

          l_Xp = l_X;
          l_Yp = l_Y;
        } else l_bStop = true;

        l_oldProperName = l_ProperName;

        if (l_bStop) {
          l_consts = null;
          l_consts = new Constellation();
          i = 0;
        }
      }
    }
    return al_const;
  }
Пример #9
0
    public void calculateForces(ArrayList objects) {
      for (int i = 0; i < objects.size(); i++) {
        CelestialObject obj = (CelestialObject) objects.get(i);
        ArrayList forces = obj.getForces();
        float totalForceX = 0;
        float totalForceY = 0;

        for (int j = 0; j < forces.size(); j++) {
          totalForceX += ((PVector) forces.get(j)).x;
          totalForceY += ((PVector) forces.get(j)).y;
        }

        PVector newAccel = new PVector(totalForceX / obj.getMass(), totalForceY / obj.getMass());

        obj.setAcceleration(newAccel);
      }

      for (int i = 0; i < objects.size(); i++) {
        CelestialObject obj1 = (CelestialObject) objects.get(i);
        float forceX = 0;
        float forceY = 0;
        obj1.clearForces();

        if (obj1.getClass() == Star.class) {
          println(obj1.getVelocity());
          continue;
        }

        for (int j = 0; j < objects.size(); j++) {
          CelestialObject obj2 = (CelestialObject) objects.get(j);

          if (i == j) continue;

          PVector pvDistance = PVector.sub(obj2.getPosition(), obj1.getPosition());
          //    println("distance: x:" + pvDistance.x + " y:" + pvDistance.y);
          float distance = sqrt(sq(pvDistance.y) + sq(pvDistance.x));
          float angle = degrees(atan2(pvDistance.y, pvDistance.x));

          float force = (G * obj1.getMass() * obj2.getMass()) / sq(distance);
          forceX = force * cos(radians(angle));
          forceY = force * sin(radians(angle));
          //        println("FORCES on " + obj1.getName() + ":" + forceX + "," + forceY);
          obj1.addForce(new PVector(forceX, forceY));

          println();
        }
      }
    }