You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Ruby中基于月相年龄计算月球照明百分比?

如何准确计算月球照明百分比?

我编写了一个用于计算部分月球属性的Ruby模块,参考维基百科的月相计算相关内容实现,逻辑十分简洁。但我不知道该如何准确计算月球照明百分比。

我尝试过采用线性计算方式:将朔望月(LUNAR_MONTH)的中点设为100%照明,但考虑到月球的椭圆轨道,这种线性计算可能并不准确。

或者,线性计算其实是可行的?

module LunarPhase
  LUNAR_MONTH = 29.530588853
  KNOWN_NEW_MOON = DateTime.new(2000, 1, 6, 6, 14, 0).amjd.to_f

  module ClassMethods
    def percent(time = DateTime.now)
      age(time) / LUNAR_MONTH
    end

    def age(time = DateTime.now)
      (time.amjd - KNOWN_NEW_MOON).abs % LUNAR_MONTH
    end

    def illumination(time = DateTime.now)
      # this is linear but maybe we need something more complicated
      # because I see a difference with online calculators
      age_full = LUNAR_MONTH / 2
      diff = age_full - age(time)
      (age_full - diff.abs) / age_full
    end
  end

  extend ClassMethods
end

-- 你可以基于WTFPL许可证使用此代码

更新:我在Greg Miller的相关页面上看到了一些计算方法,但其中充满了我无法理解的常数。我非常希望了解这些计算背后的相关理论。

内容的提问来源于stack exchange,提问作者akostadinov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 10:35:26