首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用PyEphem计算阴影长度

用PyEphem计算阴影长度
EN

Stack Overflow用户
提问于 2011-04-19 18:03:21
回答 1查看 2.9K关注 0票数 8

我正在使用PyEphem,并想要计算阴影的长度(假设一根单位长度的棍子种在地上)。长度将由cot( phi ),其中phi是太阳仰角(如果我错了请纠正我)。我不确定在太阳上使用什么场??在下面的示例中,我使用了alt角度:

代码语言:javascript
复制
import ephem, math
o = ephem.Observer()
o.lat, o.long = '37.0625', '-95.677068'
sun = ephem.Sun()
sunrise = o.previous_rising(sun, start=ephem.now())
noon = o.next_transit(sun, start=sunrise)
shadow = 1 / math.tan(sun.alt)

请核对我的解释如下:

  1. 如果正切是无限的,它表示太阳直接在头顶上,没有影子。
  2. 如果切线为零,则表示太阳在地平线上,阴影是无限长的。
  3. 我不知道如何解释cot(phi)的负面结果。有人能帮我吗?

最后,我很困惑如何使用PyEphem从阴影长度倒转到下一次太阳将投出该长度的阴影时,给出一个ephem.Observer()。

我希望能在这方面提供帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-19 23:09:02

在太阳上使用什么能量场?

sun.alt是正确的。alt是一个高于地平线的高度;与北面以东的方位一起,它们定义了相对于地平线的表观位置

你的计算几乎是正确的。你忘了提供一个观察者:sun = ephem.Sun(o)

  1. 我不知道如何解释cot(phi)的负面结果。有人能帮我吗?

在这种情况下,太阳处于地平线以下。

最后,我很困惑如何使用PyEphem从阴影长度倒转到下一次太阳将投出该长度的阴影时,给出一个ephem.Observer()。

下面是一个给定函数的脚本:g(date) -> altitude计算下一次太阳将投出与现在一样长的阴影(不考虑阴影的方位方向):

代码语言:javascript
复制
#!/usr/bin/env python
import math
import ephem    
import matplotlib.pyplot as plt
import numpy as np
import scipy.optimize as opt

def main():
    # find a shadow length for a unit-length stick
    o = ephem.Observer()
    o.lat, o.long = '37.0625', '-95.677068'
    now = o.date
    sun = ephem.Sun(o) #NOTE: use observer; it provides coordinates and time
    A = sun.alt
    shadow_len = 1 / math.tan(A)

    # find the next time when the sun will cast a shadow of the same length
    t = ephem.Date(find_next_time(shadow_len, o, sun))
    print "current time:", now, "next time:", t # UTC time
    ####print ephem.localtime(t) # print "next time" in a local timezone

def update(time, sun, observer):
    """Update Sun and observer using given `time`."""
    observer.date = time
    sun.compute(observer) # computes `sun.alt` implicitly.
    # return nothing to remember that it modifies objects inplace

def find_next_time(shadow_len, observer, sun, dt=1e-3):
    """Solve `sun_altitude(time) = known_altitude` equation w.r.t. time."""
    def f(t):
        """Convert the equation to `f(t) = 0` form for the Brent's method.

        where f(t) = sun_altitude(t) - known_altitude
        """
        A = math.atan(1./shadow_len) # len -> altitude
        update(t, sun, observer)
        return sun.alt - A

    # find a, b such as f(a), f(b) have opposite signs
    now = observer.date # time in days
    x = np.arange(now, now + 1, dt) # consider 1 day
    plt.plot(x, map(f, x))
    plt.grid(True)
    ####plt.show()
    # use a, b from the plot (uncomment previous line to see it)
    a, b = now+0.2, now+0.8

    return opt.brentq(f, a, b) # solve f(t) = 0 equation using Brent's method


if __name__=="__main__":
    main()

输出

代码语言:javascript
复制
current time: 2011/4/19 23:22:52 next time: 2011/4/20 13:20:01
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5720633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档