Astronomy Demo

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa® 365 Puzzlers  Calendar 2017

Mensa® 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

 

Problem Description

Here's a program demonstrating most of the capabilities of a Delphi TAstronomy unit.  These include:

bulletPosition of Sun, Moon and the planets for any given date and time.
bulletSun and Moon rise and set times for any date.
bulletFull and New Moon prediction
bulletSolar and Lunar eclipse prediction.
bulletAnalemma diagram for any given time of day.
bulletAbility to take inputs and display results in any of the four time measurement systems or five coordinate systems used by astronomers.  

Background & Techniques

Most of the code in this program is a direct translation of Basic code published by  Peter Duffett-Smith in his book "Astronomy with your Personal Computer", Second Edition, Cambridge University Press, 1990.  The above link will take you to the Amazon site where there are a  few used copies available (as of 11/5/03)  in the $5 -$10 price range.    In addition to the code, each routine in the book is preceded by a few pages describing the function with much more clarity than I ever could.  Planetary motion is complex and  analytical solutions  don't exist for many problems.   In these cases, curve fit solutions, with lots (!) of numeric values  provide the answer.  

Rank beginners will be satisfied with the default time and coordinate system options.  Times are input and reported in "local time",   Greenwich Mean Time (also known as Universal time) adjusted for time zone and Daylight Savings time. Viewing location coordinates are input using geographical longitude, latitude, and height above sea level.  And coordinates by default are reported in the "horizon" system which locates an object in the sky by measuring the angle from North clockwise around the horizon (azimuth), and then the angle above the horizon (altitude).

Other time systems derive from the fact that our years really have an extra "hidden" day each year which we never see.  Viewed from a fixed position in space, we would see that the earth actually rotates 366.25 times per year!   And our days in "star time" (Sidereal time) are about 4 minutes shorter that we think they are.   Sidereal time, by the way, also comes in two flavors: Greenwich Sidereal Time and Local Sidereal time.   

Think of it this way, if the earth rotated one time per year, so that  say, Southwest Virginia always faced the Sun, we would never see a sunrise or sunset, and would have zero days in a "year", but a space observer would see that we had one day (one revolution) per year.   Thus the "lost day".  Fascinating stuff.   Pick up the Duffett-Smith book or an introductory Astronomy text to learn more about this as well as  lots more other about coordinate systems such as Equatorial,  Ecliptic,  and Galactic.    Each system defines measures similar to azimuth and altitude but measured from planes other than the horizon  ( plane of the earth's equator for Equatorial, plane of the planetary orbits for Ecliptic, and plane of our galaxy for Galactic).   

I'll warn you that, while I tested each of the converted routines against Duffett-Smith's test results as  they were coded, I have not none much testing using other than the default time and coordinate systems once routines were integrated into the TAstronomy unit.  Bug reports will be appreciated, and I'll do my best to correct them.  

Non-programmers are welcome to read on, but may want to jump to bottom of this page to download the executable program now.

Programmer's Notes:

The conversion involved manual transcription of  page after page of Basic code that looks like this random sample of a few lines in Delphi from the Nutate procedure:  (Nutation is one of the ways that the earth wobbles on its axis.)

A:=5.372616667*T;
B:=360.0*(A-INT(A));
N1:=2.591833E2+2.078E-3*T2-B;
N1:=DegToRad(N1);
N2:=2*N1;

DP:=(-17.2327-1.737E-2*T)*SIN(N1);
DP:=DP+(-1.2729-1.3E-4*T)*SIN(L2)+2.088E-1*SIN(N2);
DP:=DP-2.037E-1*SIN(D2)+(1.261E-1-3.1E-4*T)*SIN(M1);
DP:=DP+6.75E-2*SIN(M2)-(4.97E-2-1.2E-4*T)*SIN(L2+M1);
DP:=DP-3.42E-2*SIN(D2-N1)-2.61E-2*SIN(D2+M2);
DP:=DP+2.14E-2*SIN(L2-M1)-1.49E-2*SIN(L2-D2+M2);
DP:=DP+1.24E-2*SIN(L2-N1)+1.14E-2*SIN(D2-M2);

DOB:=(9.21+9.1E-4*T)*CoS(N1);
DOB:=DOB+(5.522E-1-2.9E-4*T)*COS(L2)-9.04E-2*COS(N2);
DOB:=DOB+8.84E-2*COS(D2)+2.16E-2* COS(L2+M1);
DOB:=DOB+1.83E-2*COS(D2-N1)+1.13E-2*COS(D2+M2);
DOB:=DOB-9.3E-3*COS(L2-M1 )-6.6E-3*COS(L2-N1);

Maybe a  thousand additional  lines of similar code complete the computational portion of the unit.

There is nothing else particularly complex in the code although well over 3000 lines of code make it one of the larger program posted here.  And if an error needs to be corrected, debugging can be a bit tedious because intermediate results are difficult to verify.  

 I replaced Duffett-Smith's date calculations with standard Delphi date-time fields which required changes to the procedures in a few places.  And graphic displays were added showing Sun and Moon rise and set locations and Moon phase and Analemmas. .   These are similar to those previously posted for solar info only in our Solar Position  program    

Addendum January 31, 2007:  A viewer last month asked for the addition of "Twilight" times.  I finally got around to it today.   Twilight is the time before sunrise or after sunset where some visibility exists.  Such regulations as VFR (Visual Flight Rules)  and hunting use twilight to define daylight times  when a pilot can fly or a hunter hunt.   It turns out that, as in most things astronomical,  there are  multiple definitions.  

bulletCivil twilight (the kind referred to above) begins in the morning when the center of the sun is 6° below the horizon and ends at sunrise.    In  the evening it begins at sunset and ends when the sun is again 6° below the horizon.  During this period the idea is that objects on the ground can be clearly distinguished.
bulletNautical Twilight is similarly defined except the reference sun position is 12°   below the horizon.  Here, in theory, there is enough light for sailors to take navigational readings which require visibility of the stars and the horizon. 
bulletFinally, Astronomical Twilight is relative to 18° below the horizon and assumes that  this this the beginning and ending position when  any refracted light from the sky  reaches above the horizon.

 .   All three versions are now listed in the sun position statistics.   

April 19,2015:  Version 2 of The AstroDemo program posted today has two new features:

bulletAngles can now be entered and displayed in decimal degree format as well as degrees, minutes, seconds.
bulletSolar Analemmas now have a panel displayed with the sun azimuth and altitude for current date and time.  An "Animate" button will advance the display day by day for the currently specified time of day.  Choice of Shadow or Camera view has also been moved from the Options menu to this panel.

      Running/Exploring the Program 

bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

April 19, 2015:Done!   Accept angles as decimal degrees as well as DMS (Degree, Minute, Second) format..   
Lots of opportunities using 3D graphics to reveal the mysteries of the Universe! (And the coordinate systems that measure it.)
The orbital calculations for each planet require values for six planetary elements.  Pluto's elements change over time and must be obtained from a published source for any specific year.    I did not include a table of these values, and I  do not how much the elements change over time.  Currently an error message is given if the user inquires about the location of Pluto.   Is there a better solution?   
I suspect that it would not be too difficult to add stars to the list of objects that could be located in the sky.    Probably just a matter of converting the Galactic coordinates of some named objects to the Horizon coordinate system. 

 

Original: November 05, 2003

Modified:  May 15, 2018

 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2018, Gary Darby    All rights reserved.