[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
Background & Techniques
Another case of "fool's rush in"... I had little idea what I was getting into when I decided to calculate sunset positions for a plaque I'm planning. The plaque will be an outline of the mountain peaks from visible from the computer room with sunset positions and dates marked.
Astronomers have several coordinate systems and several time measurement systems to choose from. Useful for them I suppose, but complicated for the beginner. After working for several days on a comprehensive TAstronomy component, I scaled back to the current effort. Latitude, longitude, azimuth and altitude are the only user interface concepts required.
Latitude is the North/South angle between the equator and our position (0 to 90 degrees, North or South). Longitude is the angle that we are around from a circle that rune through the poles and Greenwich, England (0 to 180 degrees, East or West). Altitude measures the angle from the horizon to some object in the sky (-90 to 90 degrees, only 0 to 90 visible). Azimuth is the angle measured clockwise from north to the point on the horizon directly under the object ( 0 to 360 degrees)).
The central subroutine, SunPos, is adapted from C code written Joe Cychosz, Purdue University CADLAB. I fixed an error or two, and changed several equations to more accurate versions found in other programs and texts. The current version seems to match pretty well with all the calibration points I've tried - if you find any significant errors, please let me know.
Most of the rest of the code for the basic problem is straightforward, a GetBaseData procedure validates and converts input fields (latitude, longitude, date, time, and time-zone/daylight saving time offsets). A TMemo control displays the results. A plot is also created showing the azimuth angles for sunrise and sunset. A TPaintBox control provides the canvas for drawing this plot and the analemma (see below). TDateTimePicker controls provide the fields for inputting date and time info.
The analemma plot was an afterthought. An analemma is a that figure 8 shaped graphic that appears on globes and sundials. It describes the position of the sun if observed at the same time each day for a year. If the earth's orbit were circular and we weren't tilted in relation to the plane of our orbit, the plot would be a dot, i.e. the sun would be at the same location each day. Since we're tilted 23.5 degrees, the sun appears high in the sky when our pole is pointed toward the sun and lower 6 months later when we're pointed away. The analemma in this case should appear as a straight line, highest on June 21 and lowest on Dec 21 if you live in the northern hemisphere, reversed in the southern hemisphere. The second complication arises because the earth travels in an elliptical rather that circular orbit. This causes its orbital speed around the sun to vary throughout the year and thus sometimes we are ahead of, and sometimes behind the average position. Our clocks aren't smart enough to speed up and slow down as the the earth's speed changes so if we measure the sun's position at the same clock time each day, sometimes we measure early (left of the mean line) and sometimes late (right of the mean line). The result is the analemma. In fact the analemma on a sundial is there to tell us how many minutes we must add or subtract from solar time to get back to average time.
There are three plot options for the analemma, each with problems. "Shadow" mode is the projection of the tip of the shadow of a vertical stick onto the ground - for early and late times, the shadows get long (infinite at rising and setting times) which can cause scaling problems. "Camera South" draws the analemma as a projection onto a south facing vertical plane. In this version, a "fisheye lens" effect distorts the figure for early and late times. I think I figured how to point the camera in a specific direction (using user input date and time) to get better images. None of this has really been verified, I think that they mostly look reasonable except when measured near the horizon. The toughest problem was adjusting the scaling and panning so that the analemma remains reasonably positioned in the plot area for different times.
A discussion of analemma math really needs graphic aids but my pages of scribblings aren't up to publishing quality so I'll defer for a separate Math Topics page in the future. There are some good definitions and images at this Wikipedia entry
Addendum - August 5, 2003: A viewer from New Zealand pointed that I had his sun rising in the evening and setting in the morning. A slight southern hemisphere glitch was the cause. It is fixed with today's posting. As usual, I found another problem; the analemma graph only worked after the "Sunrise Sunset" button had been clicked. Fixed that one also.
Addendum - July 23, 2004: Another viewer, Denmark this time, is working on a program to predict the Civil Sunrise and Sunset times used to define daylight hours for pilots flying under Visual Flight Rules (VFR). Here's a version a that displays that data. Civil twilight starts and ends when the sun is 6 degrees below the horizon.
Addendum April 6, 2005: This is version 2.0 corrects several minor errors and adds an enhancement or two.
Running/Exploring the Program
Suggestions for Further Explorations
Copyright © 2000-2017, Gary Darby All rights reserved.