python正方形阴影面积计算_使用PyEphem计算阴影长度

what field to use on the Sun?

sun.alt是正确的。alt是地平线以上的高度;加上北面以东的方位角,它们定义了相对于地平线的{a1}。在

你的计算几乎是正确的。您忘了提供观察者:sun = ephem.Sun(o)。在I don't know how to interpret negative results from cot(phi). Can

someone help me?

在这种情况下,太阳在地平线以下。在Finally, I'm confused about how to use

PyEphem to work backwards from a

shadow length to the next time when

the sun will cast a shadow of that

length, given an ephem.Observer().

下面是一个给定函数的脚本:g(date) -> altitude计算下一次太阳将投射与现在相同长度的阴影时(不考虑阴影的方位角方向):#!/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()

输出

^{pr2}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
利用Python计算太阳高度角可以使用天文学公式来实现。其中,太阳高度角是指太阳在天空中的位置,可以用来计算太阳的高度和仰角。 首先,我们需要获取当前的日期、时间和地理位置的经纬度。可以使用Python中的datetime库来获取日期和时间,可以通过调用API获取地理位置的经纬度。 接下来,我们可以使用天文学公式计算太阳高度角。公式如下: cos(α) = sin(δ) * sin(φ) + cos(δ) * cos(φ) * cos(H) 其中,α是太阳高度角,δ是太阳赤纬,φ是地理位置的纬度,H是当地的时角。 我们可以使用Python中的math库来计算sin、cos等数学函数。首先,我们需要计算太阳的赤纬和时角,然后将它们带入公式中计算太阳高度角。 最后,我们将计算出来的太阳高度角打印出来作为结果。以下是一个简单的示例代码: ``` import datetime import math # 获取当前日期和时间 now = datetime.datetime.now() # 获取地理位置的经纬度 latitude = 37.7749 # 纬度 longitude = -122.4194 # 经度 # 计算太阳高度角 def calculate_sun_altitude(now, latitude, longitude): # 计算一年中的第几天 day_of_year = now.timetuple().tm_yday # 计算时角 h = (now.hour + now.minute / 60 + now.second / 3600) / 24 * 360 # 计算太阳赤纬 declination = 23.45 * math.sin(math.radians(360 / 365 * (day_of_year - 81))) # 计算太阳高度角 altitude = math.degrees(math.asin(math.sin(math.radians(declination)) * math.sin(math.radians(latitude)) + math.cos(math.radians(declination)) * math.cos(math.radians(latitude)) * math.cos(math.radians(h)))) return altitude # 调用函数计算太阳高度角 altitude = calculate_sun_altitude(now, latitude, longitude) # 打印结果 print("太阳高度角:", altitude) ``` 请注意,以上代码只是一个简单的示例,实际上,在计算太阳高度角时还需要考虑一些其他因素,例如地平方向的大气折射等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值