月亮/月相算法 [英] Moon / Lunar Phase Algorithm

查看:27
本文介绍了月亮/月相算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道一种算法来计算给定日期的月相或年龄,或者找到给定年份的新月/满月的日期?

Does anyone know an algorithm to either calculate the moon phase or age on a given date or find the dates for new/full moons in a given year?

谷歌搜索告诉我答案在某本天文学书籍中,但我真的不想买一整本书,因为我只需要一页.

Googling tells me the answer is in some Astronomy book, but I don't really want to buy a whole book when I only need a single page.

更新:

我应该更好地修饰我关于谷歌搜索的陈述.我确实找到了仅在某些时间段内有效的解决方案(例如 1900 年代);以及基于三角的解决方案,其计算成本比我想要的要高.

I should have qualified my statement about googling a little better. I did find solutions that only worked over some subset of time (like the 1900's); and the trig based solutions that would be more computationally expensive than I'd like.

S Lott 在他的 Python 书中有几种算法可以计算给定年份的复活节,大多数算法不到 10 行代码,有些可以在公历的所有日子里工作.寻找三月的满月是寻找复活节的关键部分,所以我认为应该有一种算法不需要三角,并且适用于公历中的所有日期.

S Lott in his Python book has several algorithms for calculating Easter on a given year, most are less than ten lines of code and some work for all days in the Gregorian calendar. Finding the full moon in March is a key piece of finding Easter so I figured there should be an algorithm that doesn't require trig and works for all dates in the Gregorian calendar.

推荐答案

前段时间我将一些代码移植到 Python 中.我打算只是链接到它,但事实证明它同时从网上掉下来了,所以我不得不把它擦掉并重新上传.请参阅 moon.py 其中源自 John Walker 的 moontool.

I ported some code to Python for this a while back. I was going to just link to it, but it turns out that it fell off the web in the meantime, so I had to go dust it off and upload it again. See moon.py which is derived from John Walker's moontool.

我找不到关于这两个时间跨度准确的参考,但似乎作者非常严谨.这意味着是的,它确实使用了 trig,但我无法想象你会使用它来做什么,这会使其在计算上令人望而却步.Python 函数调用开销可能超过了三角操作的成本.计算机的计算速度非常快.

I can't find a reference for this for what time spans it's accurate for either, but seems like the authors were pretty rigorous. Which means yes, it does use trig, but I can't imagine what the heck you would be using this for that would make it computationally prohibitive. Python function call overhead is probably more than the cost of the trig operations. Computers are pretty fast at computing.

代码中使用的算法来源于以下来源:

The algorithms used in the code are drawn from the following sources:

米厄斯,让.天文算法.里士满:Willmann-Bell,1991 年.ISBN 0-943396-35-2.

必备;如果你只买一本书,请确保是这本书.算法以数学方式呈现,而不是作为计算机程序,但实现本书中许多算法的源代码可以从 QuickBasic、Turbo Pascal 或 C 中的出版商单独订购.Meeus 提供了许多对调试至关重要的计算示例您的代码,并且经常提出几种算法,它们在准确性、速度、复杂性和长期(世纪和千年)有效性之间进行了不同的权衡.

A must-have; if you only buy one book, make sure it's this one. Algorithms are presented mathematically, not as computer programs, but source code implementing many of the algorithms in the book can be ordered separately from the publisher in either QuickBasic, Turbo Pascal, or C. Meeus provides many worked examples of calculations which are essential to debugging your code, and frequently presents several algorithms with different tradeoffs among accuracy, speed, complexity, and long-term (century and millennia) validity.

达菲特-史密斯,彼得.实用天文学与您的计算器.第三版.剑桥:剑桥大学出版社,1981 年.ISBN 0-521-28411-2.

尽管标题中有计算器一词;如果您有兴趣开发计算行星位置、轨道、日食等的软件,这是一个有价值的参考.提供了比 Meeus 更多的背景信息,这有助于那些尚未精通天文学的人学习经常令人困惑的术语.给出的算法比 Meeus 提供的算法更简单、更不准确,但适用于大多数实际工作.

Despite the word Calculator in the title; this is a valuable reference if you're interested in developing software which calculates planetary positions, orbits, eclipses, and the like. More background information is given than in Meeus, which helps those not already versed in astronomy learn the often-confusing terminology. The algorithms given are simpler and less accurate than those provided by Meeus, but are suitable for most practical work.

这篇关于月亮/月相算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆