java - 普利瑟姆斯的日位置 "A Practical Analytic Model for Daylight"

标签 java processing

我正在尝试实现 A Practical Analytic Model for Daylight在处理中并将其投影到二维 Canvas 上。 到目前为止,一切都工作正常,除了太阳方位角的一个棘手问题。

当我为一天中的时间设置动画时,太阳会在特定时间跳到相反的位置。 发生这种情况是因为方位角从 -90 度变为 +90 度,反之亦然。 我不确定这是否是论文的限制,或者我在计算太阳位置时犯了一个错误。 据我了解,方位角应该在 0 到 360 度之间。

有人已经实现了 Preetham 论文并可以帮助我吗?

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

感谢您的帮助。 HG

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))));
}

最佳答案

我还没有尝试过,所以它可能不起作用(取决于我没有详细研究的公式),但您可以使用 atan2 函数代替 atan,它可以提供完整的 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 - 普利瑟姆斯的日位置 "A Practical Analytic Model for Daylight",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14156026/

相关文章:

java - 数组元素具有空字段

使用网络摄像头进行 Java 运动检测

processing - 使用 Minim 获取处理频率

java - 在使用处理库的 Java 应用程序中使用 updatePixels() 时遇到问题

java - 我正在尝试使用具有随机位置的数组和类创建随机对象?

java - ParseQuery - 正确处理 IndexOutOfBoundsException - Parse.com?

java - 将时间/日期时间与时区信息完整提取到 Java8 OffsetTime/OffsetDateTime 中

java - 我们可以实例化一个抽象类吗?

java - 为什么有些方法中泛型参数<T>会变成<S>

html - 处理草图无法在 Web 浏览器中正确呈现