Wednesday, May 7, 2008

Adding Equinoxes & Solstices

The current clock design has been extended by the inclusion of indicators for the equinoxes and solstices. The accuracy of the calculated equinox and solstice times is good - within a minute or two of the official values. Most of the error comes from having to estimate the difference between Dynamical Time (based on atomic clocks) and Universal Time (based on the slowly and unpredictably decreasing rotation of the Earth). I am indebted to Jean Meeus for his book Astronomical Algorithms which not only explains all of these matters, but offers straightforward means of computing them. (Thanks also to my colleague James Stolpa for recommending the book, and for having a copy on hand to loan to me.) Regrettably, the book is out of print, but used copies can be found. (I hope to receive my own copy soon.)

In this version of the clock, the equinox and solstice indicators are confined to the "year" band, but future versions will also show them in the month, week, hour and minute bands as the date of an equinox or solstice arrives within their scope. I hope to find time to add lunar phases after that. If there were a programmatic means of obtaining a client's latitude, I'd add sunrise and sunset indicators in a heartbeat.

Ideally, you'll see an active analog clock here, rendered using SVG, and animated using Javascript. It works in Safari, anyway.

Lessons Learned

  • When deleting items returned by the DOM element.getElementsByTagNameNS method, it is important to delete them from last-to-first. Deleting them from first-to-last produces unpredictable results - sometimes everything is deleted, sometimes only a fraction of the items are deleted.
  • Firefox can't handle SVG symbol elements using other symbol elements. Safari can.
  • Jean Meeus' book Astronomical Algorithms is wonderful. It's a shame that it's out of print.
  • The World Wide Web Consortium's Markup Validation Service validates SVG. You don't have to go to a special page; the validator recognizes SVG automatically and validates accordingly.

No comments:

Post a Comment