Newsgroup: it.scienza.astronomia
Titolo: Fasi Lunari

Qualcuno mi sa dire dove trovo le formule (o il sorgente di un programma)
per calcolare con precisione le fasi lunari, l'alba e tramonto in una data
latitudine ed altezza?
grazie
-- 
questo articolo e` stato inviato via web dal servizio gratuito 
http://www.newsland.it/news
 segnala gli abusi ad 
ab...@newsland.it

 
Le formule le trovi nell'eccellente libro di Jean Meeus "Astronomical 
Algorithms". Un sorgente in Java (solo per le fasi lunari; alba e 
tramonto per una data località è un sorgente molto più lungo di questo) 
eccolo qua:
import java.awt.*;
import java.applet.*;
import java.lang.*;
public class MoonPhase extends Applet {
   public double phase;
   public double sundist, moondist;
   public double sunsize, earthsize, moonsize;
   public int width, height;
   public boolean both;
   public Image buf;
   public Graphics gBuf;
   private MoonCanvas canvas;
   public MoonCanvas2 canvas2;
   private TextField fov;
   private Font font;
   private Choice viewmenu;
   private Panel center;
   private CardLayout card;
   public Canvas current;
   private Button runbutton;
   private Scrollbar animslider;
   private PhaseThread phaseThread;
   private Thread theThread;
   private double animspeed;
   public void init() {
     Dimension d = size();
     width = d.width;
     height = d.height;
     setBackground(Color.lightGray);
     setFont(font = new Font("Helvetica", Font.PLAIN, 12));
     setLayout(new BorderLayout());
     buf = createImage(width, height);
     gBuf = buf.getGraphics();
     phaseThread = null;
     animspeed = 0.02;
     phase = 0.0;
     sundist = 1.0;
     moondist = 0.3;
     sunsize = 0.2;
     earthsize = 0.15;
     moonsize = 0.07;
     both = false;
     center = new Panel();
     center.setLayout(card = new CardLayout());
     add("Center", center);
     center.add("Top", canvas = new MoonCanvas(this));
     center.add("Earth", canvas2 = new MoonCanvas2(this));
     canvas2.update(canvas2.getGraphics());
     current = canvas;
     Panel bottom = new Panel();
     bottom.setLayout(new GridLayout(0,1));
     add("South", bottom);
     Panel panel = new Panel();
     panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
     bottom.add(panel);
     panel.add(new Label("Moon Phase (0.0 to 1.0)", Label.RIGHT));
     fov = new TextField(String.valueOf(phase), 12);
     fov.setEditable(true);
     panel.add(fov);
     runbutton = new Button("Animate");
     panel.add(runbutton);
     panel = new Panel();
     panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
     bottom.add(panel);
     panel.add(new Label("Point of View", Label.RIGHT));
     viewmenu = new Choice();
     viewmenu.addItem("Top View");
     viewmenu.addItem("Earth View");
     viewmenu.addItem("Both");
     viewmenu.select(0);
     panel.add(viewmenu);
   }
   public void destroy() {
     gBuf.dispose();
   }
   String fixString(double d) {
     String t = String.valueOf(Math.round(d*100000.0)/100000.0);
     if (t.endsWith("0001")) {
       t = t.substring(0, t.length()-4);
     }
     while (t.endsWith("0"))
       t = t.substring(0, t.length()-1);
     return t;
   }
   public synchronized boolean handleEvent(Event event) {
     if (event.target == phaseThread && 
event.id
 == Event.ACTION_EVENT) {
       phase += 0.02;
       if (phase > 1.0)
	phase--;
       current.update(current.getGraphics());
       return true;
     } else if (event.target == fov && 
event.id
 == Event.ACTION_EVENT) {
       double a = new Double(fov.getText()).doubleValue();
       if (a < 0.0)
         a = 0.0;
       if (a > 1.0)
         a = 1.0;
       fov.setText(fixString(a));
       phase = a;
       current.update(current.getGraphics());
       return true;
     } else if (event.target == runbutton && 
event.id
 == 
Event.ACTION_EVENT) {
       if (phaseThread == null) {
         phaseThread = new PhaseThread(this);
         theThread = new Thread(phaseThread);
         theThread.setPriority(Thread.MIN_PRIORITY);
         phaseThread.setTime(30);
         theThread.start();
         runbutton.setLabel("Stop");
       } else {
         theThread.stop();
	phaseThread = null;
         runbutton.setLabel("Animate");
         fov.setText(fixString(phase));
       }
       return true;
     } else if (event.target == animslider && 
event.id
 == 
Event.ACTION_EVENT) {
       animspeed = 0.02 * Math.pow(10.0, animslider.getValue());
       return true;
     } else if (event.target == viewmenu) {
       Canvas thing;
       both = false;
       switch(viewmenu.getSelectedIndex()) {
         case 2:
           both = true;
         case 0:
           card.show(center, "Top");
           canvas.update(canvas.getGraphics());
           current = canvas;
           break;
         case 1:
           card.show(center, "Earth");
           canvas2.update(canvas2.getGraphics());
           current = canvas2;
           break;
       }
       return true;
     } else {
       return super.handleEvent(event);
     }
   }
}
class MoonCanvas extends Canvas {
   private Dimension d;
   private MoonPhase top;
   private int xmid, ymid;
   private double scale;
   public MoonCanvas(MoonPhase parent) {
     top = parent;
     scale = 0.5;
     setBackground(Color.black);
     setForeground(Color.white);
   }
   private void drawCenteredString(Graphics g, String s, int x, int y) {
     FontMetrics f = getFontMetrics(getFont());
     g.drawString(s, x - f.stringWidth(s)/2, y + f.getHeight()/2);
   }
   protected void paintSun(Graphics g) {
     int size = (int)((double)d.width*scale*top.sunsize/2);
     g.setColor(Color.yellow);
     g.fillOval(xmid - size - (int)((double)d.width*scale*top.sundist),
	ymid - size, size*2, size*2);
   }
   protected void paintMoon(Graphics g) {
     int size = (int)((double)d.width*scale*top.moonsize/2);
     g.setColor(Color.darkGray);
     g.fillOval(xmid - size + (int)((double)d.width * scale * 
top.moondist *
		Math.cos(top.phase*2.0*Math.PI)),
	ymid - size - (int)((double)d.width * scale * top.moondist *
		Math.sin(top.phase*2.0*Math.PI)), size*2, size*2);
     g.setColor(Color.white);
     g.fillArc(xmid - size + (int)((double)d.width * scale * top.moondist *
		Math.cos(top.phase*2.0*Math.PI)),
	ymid - size - (int)((double)d.width * scale * top.moondist *
		Math.sin(top.phase*2.0*Math.PI)), size*2, size*2, 90, 180);
   }
   protected void paintEarth(Graphics g) {
     int size = (int)((double)d.width*scale*top.earthsize/2);
     g.setColor(Color.blue.darker());
     g.fillOval(xmid - size, ymid - size, size*2, size*2);
     g.setColor(Color.blue.brighter());
     g.fillArc(xmid - size, ymid - size, size*2, size*2, 90, 180);
   }
   protected void paintSky(Graphics g) {
     d = size();
     xmid = d.width/2;
     ymid = d.height/2;
     g.setColor(Color.black);
     g.fillRect(0, 0, d.width, d.height);
     if (top.both) {
       d.width /= 2;
       top.canvas2.paintSky(g, d.width, d.height, xmid + d.width/2, ymid);
       g.setColor(Color.black);
       g.fillRect(0, 0, d.width, d.height);
       g.setColor(Color.red);
       g.drawLine(d.width, 0, d.width, d.height);
       xmid = d.width/2;
     }
     xmid += d.width/5;
     paintSun(g);
     paintMoon(g);
     paintEarth(g);
   }
   public void paint(Graphics g) {
     paintSky(top.gBuf);
     g.drawImage(top.buf, 0, 0, this);
   }
   public void update(Graphics g) {
 
     paint(g);
   }
/* While the mouse is down, animate the moon */
   public boolean mouseDown(Event evt, int x, int y) {
     return true;
   }
   public boolean mouseUp(Event evt, int x, int y) {
     return true;
   }
}
class MoonCanvas2 extends Canvas {
   private Dimension d;
   private MoonPhase top;
   private int xmid, ymid;
   private double scale, extrasun;
   public MoonCanvas2(MoonPhase parent) {
     top = parent;
     scale = 0.2;
     extrasun = 1.05;
     setBackground(Color.black);
     setForeground(Color.white);
   }
   private void drawCenteredString(Graphics g, String s, int x, int y) {
     FontMetrics f = getFontMetrics(getFont());
     g.drawString(s, x - f.stringWidth(s)/2, y + f.getHeight()/2);
   }
   protected void paintSun(Graphics g) {
     int size = (int)((double)d.width*scale*extrasun/2);
     g.setColor(Color.yellow);
     g.fillOval(xmid - size - (int)((double)d.width * scale *
	(top.phase-0.5) * 720), ymid - size, size*2, size*2);
   }
   protected void paintMoon(Graphics g) {
     int i, limit, sign;
     int size = (int)((double)d.width*scale/2);
     double p = top.phase;
     p = p < 0.5 ? p+0.5 : p-0.5;
     limit = size;
     sign = p < 0.5 ? 1 : -1;
//    sign = 1;
     g.setColor(Color.darkGray);
     g.fillOval(xmid - size, ymid - size, size*2, size*2);
     g.setColor(Color.white);
     for (i = -limit; i <= limit; i++)
       g.drawLine(xmid + sign * (int)((double)limit *
		Math.sqrt(1.0-(double)(i*i)/((double)(limit*limit)))),
		ymid + i,
		xmid + sign * (int)((double)limit *
			Math.cos(2.0*Math.PI*p) *
           	        Math.sqrt(1.0-(double)(i*i)/((double)(limit*limit)))),
		ymid + i);
   }
   public void paintSky(Graphics g) {
     d = size();
     xmid = d.width/2;
     ymid = d.height/2;
     paintSky(g, d.width, d.height, xmid, ymid);
   }
   public void paintSky(Graphics g, int x, int y, int xm, int ym) {
     xmid = xm;
     ymid = ym;
     d.width = x;
     d.height = y;
     g.setColor(Color.black);
     g.fillRect(0, 0, x, y);
     paintSun(g);
     paintMoon(g);
   }
   public void paint(Graphics g) {
     paintSky(top.gBuf);
     g.drawImage(top.buf, 0, 0, this);
   }
   public void update(Graphics g) {
     paint(g);
   }
}
class PhaseThread implements Runnable {
   private MoonPhase top;
   private long theTime;
   public PhaseThread(MoonPhase parent) {
     super();
     top = parent;
   }
   public void setTime(int t) {
     theTime = (long)t;
   }
   public void run() {
     while (true) {
       top.deliverEvent(new Event(this, Event.ACTION_EVENT, this));
       try {
         Thread.sleep(theTime);
       } catch (InterruptedException e){}
     }
   }
}

 grazie
Nel programma (scaricabile gratuitamente) Virtual Moon Atlas trovi
informazione possibile circa la Luna, comprese le effemeridi del passato o
del futuro.
Marco
-- 
Ziel Galaxi 1 Ev. 150/750
