This isn't a very accurate treatment, though it should be good enough for sundial-type calculations. For more information on doing calculations like this one accurately, see for example Peter Duffet-Smith's book "Astronomy with Your Personal Computer", Cambridge University Press, 1985. In the program, shadow_length = height / tan(altitude) (altitude is the angle of the sun above the horizon) sin(altitude) = sin(decl)*sin(lat) + cos(decl)*cos(lat)*cos(hourangle) where hourangle is the time before/since *solar* noon (15 degrees per hour) and decl is the sun's declination (celestial latitude, zero on the equator). tan(decl) = sin(RA) * tan(23.4 degrees) where the 23.4 is from the inclination of the earth's equator to the ecliptic (plane of earth's orbit around the sun), and where RA is the Sun's "right ascension", (celestial longitude, zero at the spring equinox). Now as a first approximation, you could say that RA increases uniformly from zero at the spring equinox (whose date & time varies about a day from year to year, but is generally around the familiar March 20). That uniform approximation gives the "mean" position of the sun. But it's not very accurate: the slope of the earth's orbit, and to a lesser extent its ellipticity, make RA vary nonuniformly. The difference between the sun's true RA and the mean RA is the "equation of time" ET, whose range is about +/- 15 minutes. It'd be possible to have a formula for that, but it's much easier to use a table, so the program includes one. So: RA = (days_since_equinox / 365.25) * 360 degrees + ET (where ET is the equation of time, tabulated here in degrees). And, if "now" is the clock-time (hours), hourangle = (now - local_solar_noon) * 15 degrees/hour where, assuming you measure "now" and "local_solar_noon" in hours and longitude in degrees, local_solar_noon = 12 - (longitude - timezone_central_longitude - ET) / 15