Package views

Source Code of views.Sun

package views;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;

import models.Coordinates;
import models.coordinates.EclipticCoordinates;
import models.coordinates.LocalHorizontalCoordinates;
import models.coordinates.UserCoordinates;

/**
*
* @author francois
*
*/
public class Sun extends Astre {

  protected static int paintWidth = 20;
  protected static int paintHeight = 20;

  private static final Image icon = Toolkit.getDefaultToolkit().getImage("data/img/sun_icon.png");

  /**
   * Creates the sun
   */
  public Sun() {
    color = Color.yellow;
  }

  @Override
  public void draw(Graphics g, UserCoordinates uc, Circle mapBounds) {
    LocalHorizontalCoordinates lhc = sunPosition(uc);
    if (lhc.isVisible()) {
      g.setColor(getColor());
      Point p = getProjection(lhc, mapBounds);
      g.drawImage(icon, p.x - paintWidth / 2, p.y - paintHeight / 2, paintWidth, paintHeight, null);
      //g.fillOval(p.x - paintWidth / 2, p.y - paintHeight / 2, paintWidth, paintHeight);
    }
  }

  /**
   * @param uc
   *       the user coordinates
   * @return the position of the sun in ecliptic coordinates
   */
  public static LocalHorizontalCoordinates sunPosition(UserCoordinates uc) {
    EclipticCoordinates c = sunPosition(uc.getJulianDate().getDecimalCentury());
    return Coordinates.eclipticToLocalHorizontal(c, uc);

  }

  /**
   * @param T
   *       number of centuries in the julian calendar at the current time
   * @return the ecliptic coordinates of the Sun
   */
  private static EclipticCoordinates sunPosition(double T) {
    // T date en siècles juliens
    double T2 = T * T;

    double L = Math.toRadians(279.69668) + Math.toRadians(36000.76892) * T + Math.toRadians(0.0003025) * T2;
    double M = Math.toRadians(358.47583) + Math.toRadians(35999.04975) * T - Math.toRadians(0.000150) * T2 - Math.toRadians(0.0000033) * T2 * T;
    double C = (Math.toRadians(1.919460) - Math.toRadians(0.004789) * T - Math.toRadians(0.000014) * T2) * Math.sin(M) + (Math.toRadians(0.020094) - Math.toRadians(0.0001) * T) * Math.sin(2 * M) + Math.toRadians(0.000293) * Math.sin(3 * M);

    double Omega = Math.toRadians(259.18) - Math.toRadians(1934.142) * T;

    double lambda = L + C - Math.toRadians(0.00569) - Math.toRadians(0.00479) * Math.sin(Omega);

    return new EclipticCoordinates(lambda, 0.0);
  }

}
TOP

Related Classes of views.Sun

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.