gpt4 book ai didi

c - c中的日出日落时间

转载 作者:太空狗 更新时间:2023-10-29 17:27:10 25 4
gpt4 key购买 nike

在我的 C 应用程序中,我想计算给定日期、纬度和经度的日出/日落时间。我一直在网上搜索,但找不到可用的示例。

我试图实现这个示例: http://souptonuts.sourceforge.net/code/sunrise.c.html

但是这个示例没有正常工作。

是否有可以在我的应用程序中轻松实现的简单 C 源代码或方法?

编辑:
我在这个 link 上实现了代码但它给了我错误的日落/日出值。我也尝试了 Saul 的链接 here但它也给了我错误的结果。
我有41N,28E位置。当我尝试这些代码时,两个示例都表示日出时间约为 10:13,日落时间为 23:24。但正确的值是 06:06、20:13。
我无法理解这个问题。

最佳答案

计算 sunrise / sunset time 的十个简单步骤给定日期、纬度和经度

  1. 首先计算一年中的第几天

    N1 = floor(275 * 月/9)N2 = floor((month + 9)/12)N3 = (1 + floor((year - 4 * floor(year/4) + 2)/3))N = N1 - (N2 * N3) + 天 - 30

  2. 将经度转换为小时值并计算大概时间

    lngHour = 经度/15

    如果需要上升时间: t = N + ((6 - lngHour)/24)如果需要设置时间: t = N + ((18 - lngHour)/24)

  3. 计算太阳的平均距平

    M = (0.9856 * t) - 3.289

  4. 计算太阳的真经度

    L = M + (1.916 * sin(M)) + (0.020 * sin(2 * M)) + 282.634注意:L 可能需要通过加/减 360 调整到 [0,360) 范围内

5a。计算太阳的赤经

RA = atan(0.91764 * tan(L))
NOTE: RA potentially needs to be adjusted into the range [0,360) by adding/subtracting 360

5b。赤经值需要和L在同一象限

Lquadrant  = (floor( L/90)) * 90
RAquadrant = (floor(RA/90)) * 90
RA = RA + (Lquadrant - RAquadrant)

5c。赤经值需要换算成小时

RA = RA / 15
  1. 计算太阳的赤纬

    sinDec = 0.39782 * sin(L)cosDec = cos(asin(sinDec))

7a。计算太阳的地方时角

cosH = (cos(zenith) - (sinDec * sin(latitude))) / (cosDec * cos(latitude))

if (cosH > 1)
the sun never rises on this location (on the specified date)
if (cosH < -1)
the sun never sets on this location (on the specified date)

7b。计算完H并换算成小时

if if rising time is desired:
H = 360 - acos(cosH)
if setting time is desired:
H = acos(cosH)

H = H / 15
  1. 计算本地上升/下降的平均时间

    T = H + RA - (0.06571 * t) - 6.622

  2. 调整回 UTC

    UT = T - lngHour注意:UT 可能需要通过加/减 24 调整到 [0,24) 范围内

  3. 将UT值转换为本地时区的纬度/经度

    localT = UT + localOffset

关于c - c中的日出日落时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7064531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com