这个问题在三年多前就被提出过了.给出了答案,但是我发现解决方案存在问题.
下面的代码在R.我已经将它移植到另一种语言,但是直接在R中测试了原始代码,以确保问题不在于我的移植.
sunPosition <- function(year, month, day, hour=12, min=0, sec=0,
lat=46.5, long=6.5) {
twopi <- 2 * pi
deg2rad <- pi / 180
# Get day of the year, e.g. Feb 1 = 32, Mar 1 = 61 on leap years
month.days <- c(0,31,28,31,30,31,30,31,31,30,31,30)
day <- day + cumsum(month.days)[month]
leapdays <- year %% 4 == 0 & (year %% 400 == 0 | year %% 100 != 0) & day >= 60
day[leapdays] <- day[leapdays] + 1
# …Run Code Online (Sandbox Code Playgroud)