function for bearing
There is a very interesting discussion of the centrality of azimuth-finding in the development of mathematics and mathematical geography in: http://patriot.net/users/abdali/ftp/qibla.pdf. Among others, al-Khwarizmi was an important contributor.
Thanks Roger - that is a really excellent resource. A similar one by Sudipto Banerjee for distance that I learnt a lot from is here: http://www.biostat.umn.edu/~sudiptob/ResearchPapers/Geodesics.pdf