Calculations of the path of the Sun

后端 未结 1 1869
南方客
南方客 2021-01-04 12:37

I\'m writing several methods necessary to calculate the path of the Sun across a specific point. I have written the code using two different sources for my calculations and

相关标签:
1条回答
  • 2021-01-04 13:19

    You pass the longitude to localSolarTime() as degrees, and then you divide that by 60, with a comment claiming this is in order to convert to minutes of arc. This is wrong; your later calculations require degrees, and even if you needed minutes of arc, you'd multiply by 60, not divide.

    This mistaken division results in a longitude of -1.3°, and when you find the angle between your local time meridian and your position, you get a large angle (about 75°). It should be a small angle, generally ±7.5°. The large angle results in a large time correction, and throws everything off.


    Update: In the updated version of the azimuth() method, the quadrant selection should be based on the hour angle of the sun, or, equivalently, on local solar time, rather than standard wall clock time. And, the hour angle used in all calculations should not be rounded. Rather than testing four different quadrants, the method could look like this:

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

    Finally, you are passing dcLong in as the lat parameter of the azimuth() method; this should be dcLat.

    I'd recommend using radians internally throughout, and only converting from and to degrees on input and output. This will help prevent mistakes, and cut down on rounding errors and unnecessary clutter.

    0 讨论(0)
提交回复
热议问题