我正在尝试在Processing中实现A Practical Analytic Model for Daylight并将其投影在2d画布上。
到目前为止,一切工作正常,但太阳方位角存在令人讨厌的问题。

当我设置一天中的时间动画时,太阳在特定时间跳到对面的位置。
发生这种情况是因为方位角从-90度变为+90度,反之亦然。
我不确定这是否是纸张的限制,还是我在计算太阳位置时出错。
据我了解,方位角应在0到360度之间。

任何人都已经实施了Preetham论文,可以为我提供帮助吗?

这是我的代码来计算太阳位置。
您可以在此处下载完整的处理草图:
https://dl.dropbox.com/u/42247259/PreethamSky.zip

谢谢你的帮助。


private void calculateSolarPosition() {
    float t = solarTime(standardTime, dayOfYear, standardMeridian, longitude);
    float delta = solarDeclination(dayOfYear);
    thetaS = angleFromSunToZenith(t, delta, latitude);
    phiS = sunAzimuth(t, delta, latitude);
}

/// Returns the solar time at a certain geographic place, day of year and standard time.
private float solarTime(float standardTime, int dayOfYear, float standardMeridian, float longitude) {
    return (float)(standardTime + 0.17 * sin(4 * PI * (dayOfYear - 80) / 373) - 0.129 * sin(2 * PI * (dayOfYear - 8) / 355) + 12 * (standardMeridian - longitude) / PI);
}


/// Returns the solar declination. Solar declination is the angle between the rays of the sun and the
/// plane of the earth's equator.
private float solarDeclination(int dayOfYear) {
    return (float)(0.4093 * sin(2 * PI * (dayOfYear - 81) / 368.0));
}


/// Returns the angle from the sun to the zenith in rad.
private float angleFromSunToZenith(float solarTime, float solarDeclination, float latitude) {
    return (float)(PI / 2 - asin(sin(latitude) * sin(solarDeclination) -  cos(latitude) * cos(solarDeclination) * cos(PI * solarTime / 12)));
}


/// Returns the azimuth of the sun in rad. Azimuth is the angle between a line to south and the sun.
private float sunAzimuth(float solarTime, float solarDeclination, float latitude) {
    return (float)-(atan((-cos(solarDeclination) * sin(PI * solarTime / 12)) /
        (cos(latitude) * sin(solarDeclination) - sin(latitude) * cos(solarDeclination) *
        cos(PI * solarTime / 12.0))));
}

最佳答案

我没有尝试过,所以它可能不起作用(取决于我尚未详细研究的公式),但是可以使用atan函数代替atan2,它给出完整的360度结果。

/// Returns the azimuth of the sun in rad. Azimuth is the angle between a line to south and the sun.
    private float sunAzimuth(float solarTime, float solarDeclination, float latitude) {
    return (float)-(atan2((-cos(solarDeclination) * sin(PI * solarTime / 12)),
        (cos(latitude) * sin(solarDeclination) - sin(latitude) * cos(solarDeclination) *
        cos(PI * solarTime / 12.0))));
}


此功能考虑分子和分母的符号来决定角度应在哪个象限中。

关于java - Preethams中的太阳位置“日光的实用分析模型”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14156026/

10-10 22:45