- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在编写几种必要的方法来计算太阳穿过特定点的路径。我已经使用两个不同的来源编写代码进行计算,但都没有产生预期的结果。来源是:http://www.pveducation.org/pvcdrom/properties-of-sunlight/suns-position和 http://www.esrl.noaa.gov/gmd/grad/solcalc/solareqns.PDF
注意:弧分的度数是 Deg * 60 分。
localSolartime:我已将经度转换为“分钟”,从 localStandardTimeMeridian 方法派生的本地标准时间子午线 (lstm) 返回一个以“分钟”为单位的值,而 equationOfTime 也在“分钟'。使用 pveducation 中的方程式,我计算了时间校正,它解释了给定时区内的小时间变化。当我将此结果和本地时间(以分钟为单位)应用于本地太阳时 (lst) 方程时,结果为 676.515(此时),这对我来说没有任何意义。据我了解,地方太阳时代表相对于太阳的时间,当太阳位于天空中的最高点时,在本地被认为是太阳正午。 676.515 没有意义。有没有人知道是什么原因造成的。
HourAngle:我希望一旦我修复了 localSolarTime 方法,就不需要更正它了。
我已选择华盛顿特区作为纬度和经度。 Zenith 和 Azimuth 读数都应为正值,此时对于我所在的地区,分别为 66 和 201。
public class PathOfSun {
static LocalTime localTime = LocalTime.now();
static double dcLat = 38.83;
static double dcLong = -77.02;
static DecimalFormat df = new DecimalFormat("#.0");
public static void main(String [] args) {
int day = dayOfYear();
double equationOfTime = equationOfTime(day);
double lstm = localTimeMeridian();
double lst = localSolarTime(equationOfTime, dcLong, lstm);
double declination = declination(day);
double hourAngle = hourAngle(lst);
double zenith = zenith(dcLat, declination, hourAngle);
double azimuth = azimuth(dcLong, declination, zenith, hourAngle);
}
//Longitude of timezone meridian
public static double localTimeMeridian() {
TimeZone gmt = TimeZone.getTimeZone("GMT");
TimeZone est = TimeZone.getTimeZone("EST");
int td = gmt.getRawOffset() - est.getRawOffset();
double localStandardTimeMeridian = 15 * (td/(1000*60*60)); //convert td to hours
//System.out.println("Local Time Meridian: " + localStandardTimeMeridian);
return localStandardTimeMeridian;
}
//Get the number of days since Jan. 1
public static int dayOfYear() {
Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
int dayOfYear = localCalendar.get(Calendar.DAY_OF_YEAR);
//System.out.println("Day: " + dayOfYear);
return dayOfYear;
}
//Emperical equation to correct the eccentricity of Earth's orbit and axial tilt
public static double equationOfTime (double day) {
double d =(360.0/365.0)*(day - 81);
d = Math.toRadians(d);
double equationTime = 9.87*sin(2*d)-7.53*cos(d)-1.54*sin(d);
//System.out.println("Equation Of Time: " + equationTime);
return equationTime;
}
//The angle between the equator and a line drawn from the center of the Sun(degrees)
public static double declination(int dayOfYear) {
double declination = 23.5*sin((Math.toRadians(360.0/365.0))*(dayOfYear - 81));
//System.out.println("Declination: " + df.format(declination));
return declination;
}
//Add the number of minutes past midnight localtime//
public static double hourAngle(double localSolarTime) {
double hourAngle = 15 * (localSolarTime - 13);
System.out.println("Hour Angle: " + df.format(hourAngle)); //(degrees)
return hourAngle;
}
//Account for the variation within timezone - increases accuracy
public static double localSolarTime(double equationOfTime, double longitude, double lstm) {
//LocalSolarTime = 4min * (longitude + localStandardTimeMeridian) + equationOfTime
//Time Correction is time variation within given time zone (minutes)
//longitude = longitude/60; //convert degrees to arcminutes
double localStandardTimeMeridian = lstm;
double timeCorrection = (4 * (longitude + localStandardTimeMeridian) + equationOfTime);
System.out.println("Time Correction: " + timeCorrection); //(in minutes)
//localSolarTime represents solar time where noon represents sun's is highest position
// in sky and the hour angle is 0 -- hour angle is negative in morning, and positive after solar noon.
double localSolarTime = (localTime.toSecondOfDay() + (timeCorrection*60)); //(seconds)
localSolarTime = localSolarTime/(60*60); //convert from seconds to hours
//Convert double to Time (HH:mm:ss) for console output
int hours = (int) Math.floor(localSolarTime);
int minutes = (int) ((localSolarTime - hours) * 60);
//-1 for the daylight savings
Time solarTime = new Time((hours-1), minutes, 0);
System.out.println("Local Solar Time: " + solarTime); //hours
return localSolarTime;
}
public static double azimuth(double lat, double declination, double zenith, double hourAngle) {
double azimuthDegree = 0;
double elevation = 90 - zenith;
elevation = Math.toRadians(elevation);
zenith = Math.toRadians(zenith);
lat = Math.toRadians(lat);
declination = Math.toRadians(declination);
hourAngle = Math.round(hourAngle);
hourAngle = Math.toRadians(hourAngle);
//double azimuthRadian = -sin(hourAngle)*cos(declination) / cos(elevation);
double azimuthRadian = ((sin(declination)*cos(lat)) - (cos(hourAngle)*cos(declination)*
sin(lat)))/cos(elevation);
//Account for time quadrants
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
if(hour > 0 && hour < 6) {
azimuthDegree = Math.toDegrees(acos(azimuthRadian));
}
else if(hour >= 6 && hour < 12) {
azimuthDegree = Math.toDegrees(acos(azimuthRadian));
azimuthDegree = 180 - azimuthDegree;
} else if (hour >= 12 && hour < 18) {
azimuthDegree = Math.toDegrees(acos(azimuthRadian));
azimuthDegree = azimuthDegree - 180;
} else if (hour >= 18 && hour < 24) {
azimuthDegree = Math.toDegrees(acos(azimuthRadian));
azimuthDegree = 360 - azimuthDegree;
}
System.out.println("Azimuth: " + df.format(azimuthDegree));
return azimuthDegree;
}
public static double zenith(double lat, double declination, double hourAngle) {
lat = Math.toRadians(lat);
declination = Math.toRadians(declination);
hourAngle = Math.round(hourAngle);
hourAngle = Math.toRadians(hourAngle);
//Solar Zenith Angle
double zenith = Math.toDegrees(acos(sin(lat)*sin(declination) + (cos(lat)*cos(declination)*cos(hourAngle))));
//Solar Elevation Angle
double elevation = Math.toDegrees(asin(sin(lat)*sin(declination) + (cos(lat)*cos(declination)*cos(hourAngle))));
System.out.println("Elevation: " + df.format(elevation));
System.out.println("Zenith: " + df.format(zenith));
return zenith;
}
}
重申一下,星期、本地时间子午线完全正确,时差和赤纬准确但不准确。----更新输出----
-----更新-----使用散点图全天显示太阳的高度/方位角。我仍然无法计算出方位角输出。很长一段时间都是正确的,但随后它会从增加开始减少(~270-->0)。一旦我最终获得正确的输出,我一定会更新代码。
最佳答案
您将经度作为度数传递给 localSolarTime()
,然后将其除以 60,并附上一条注释,声称这是为了转换为弧分。这是错误的;您以后的计算需要度数,即使您需要弧分,您也需要乘以 60,而不是除以。
这种错误划分导致经度为 -1.3°,当您找到本地时间子午线与您所在位置之间的角度时,您会得到一个大角度(大约 75°)。应该是一个小角度,一般为±7.5°。大角度导致大的时间校正,并抛出一切。
更新:在 azimuth()
方法的更新版本中,象限选择应基于太阳的时角,或者等效地,基于本地太阳时间,而不是标准的挂钟时间。并且,所有计算中使用的小时角不应四舍五入。该方法不是测试四个不同的象限,而是如下所示:
public static double azimuth(double lat, double declination, double zenith, double hourAngle)
{
double elevation = Math.toRadians(90 - zenith);
lat = Math.toRadians(lat);
declination = Math.toRadians(declination);
hourAngle = Math.toRadians(hourAngle);
double azimuthRadian = acos(((sin(declination) * cos(lat)) - (cos(hourAngle) * cos(declination) * sin(lat))) / cos(elevation));
double azimuthDegree = Math.toDegrees(azimuthRadian);
if (hourAngle > 0)
azimuthDegree = 360 - azimuthDegree;
System.out.println("Azimuth: " + df.format(azimuthDegree));
return azimuthDegree;
}
最后,您将 dcLong
作为 azimuth()
方法的 lat
参数传入;这应该是 dcLat
。
我建议始终在内部使用弧度,并且只在输入和输出上进行角度和角度的转换。这将有助于防止错误,并减少舍入错误和不必要的困惑。
关于java - 太阳路径的计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30038320/
版本 java :10.0.1 Tomcat :8.0.36Ubuntu:18.04(64 位)Eclipse:光子(64 位) 错误:当我运行 Tomcat 服务器时,我发现了以下错误。请不要告诉我
我想将二进制文件传输到远程服务器。我为我的代码使用 SUN/ONC RPC(Linux 上的 rpcgen)。我正在使用 C。我已经为服务器和客户端编写了代码,它适用于文本文件,但是当我尝试传输二进制
我想在 Java 中使用 BouncyCaSTLe 和 PKCS11 库解密一个 CMSEnvelopedData。一切顺利,直到我遇到这个问题: 我可以成功检索收件人信息: CMSEnveloped
我低于异常 sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.ce
我在一个大型 Java 项目中工作,它有大约 400 个类。突然报错 sun.awt.image.PNGImageDecoder$PNGException: crc corruption at
我正在使用 Liferay v6.2 CE 并且出现以下错误: 2015 2:14:34 ΜΜ org.apache.catalina.startup.ContextConfig getServle
我正在学习 Java、Spring MVC 和 Eclipse。我现在正在读一本书,并试图让第一个 Spring MVC 示例运行。当我从 Eclipse 运行它时,出现此错误: INFO: TLD
我已经使用此命令创建了 CSR 请求: openssl req -out certificatecsr.csr -new -newkey rsa:2048 -keyout certificatekey
我们是三个开发 JSF 项目的人,我们之前没有接触过 JSF。奇怪的是,从 SVN check out 相同的数据,其中一名团队成员每次使用 Tomcat 7.0.27 时都会收到 404 错误。 T
我在 Apache Tomcat 7 上有一个 Web 应用程序,我的 Web 应用程序上有不受信任的证书。我的 Web 应用程序必须与另一个使用 https 的 Web 应用程序通信。但是我总是得到
在我运行以下代码时出现错误: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX
我已经从一台服务器迁移到一台新服务器。我为我的移动应用程序使用 PHP 网络服务来访问数据库中的数据。我已经安装了 SSL 证书,web 服务在浏览器和 iphone 应用程序(使用 ASIHTTPR
为什么在 HashMap 上调用 containsKey 比 get 慢? 测试:http://ideone.com/QsWXF (>15% 的差异,在 sun-jdk-1.6.0.17 上运行) 最
我是一名优秀的程序员,十分优秀!