Interesting Calculation
Interesting Calculation
Interesting Calculation
Abstract
A conceptually and mathematically concise formula for computing the solar azimuth angle has
been used by a subgroup of scientists, but for lack of documentation and publication, it has not
been well circulated. This note introduces this formula which is based on the idea of a unit
vector, 𝑺, originating from the observer’s location and pointing toward the center of the Sun.
The vector is completely determined by the coordinates of the subsolar point and of the
observer. The x- and y-components of the vector determine the solar azimuth angle, and their
use along with the function atan2, which is available in a number of programming/scripting
languages, including Fortran and Python, renders any circumstantial treatment absolutely
unnecessary. The z-component of the vector, at the same time, determines the solar zenith
angle.
1 Introduction
We recently modified a code that computes the solar irradiance on tilted surfaces. In this
process, we reviewed available formulas for computing the solar azimuth angle in particular.
Typically, there are three formulas expressing the sine, cosine and tangent of the solar azimuth
angle as functions of the declination and the zenith angle of the Sun, and the latitude and hour
angle of the observer’s point, and they can be found in nearly all the listed references. Each of
these formulas needs circumstantial treatment, which can be ponderous and not easy to
understand, to put the result from the inversion of a trigonometric function into the right
quadrant. Probst (2002), Sproul (2007), Bhatia (2014) and Soulayman (2018) provide warnings
about using these formulas and discussed at length how the treatment is performed.
Braun and Mitchell (1983) used the sine of the solar azimuth angle and devised a sophisticated
algorithm to put the result in the right quadrant. In fact, our original code was based on this
algorithm. Test runs, however, show that the algorithm gives correct results only in the
Northern extratropics.
*
Corresponding author: Tel: +1 757-951-1904, E-mail address: [email protected] (T.Zhang).
1
Neither the sine nor the cosine function alone can uniquely determine the solar azimuth angle,
since neither is an injective, or one-to-one, function in the range [-, ], or [-180, 180]. The
sine and cosine functions joined together as a pair, on the other hand, can uniquely determine
the solar azimuth angle. However, dividing the sine function by the cosine function, which
creates the tangent function, causes the information to degenerate, as the tangent function is
not a one-to-one function in the full possible range of the azimuth angle, which is why the value
from the arctangent function also needs further treatment to get the final angle in the right
quadrant. What is provided in The Nautical Almanac (2019) is one using the tangent function.
Meanwhile, a subgroup of scientists has been using a formula based on the x-, y- and z-
components of a unit vector, S, which is entirely determined by the coordinates of the observer
and the subsolar point, and the unit vector originates from the observer’s coordinates, or the
latitude and longitude, and points toward the Sun. Now the solar zenith angle is just the
arccosine of the z-component, and the solar azimuth angle is simply the atan2 of the x- and
y-components, and the atan2 here is a function that takes two separate arguments and is
available in such as Fortran and Python. Aside from the simplicity of this method, the
equation of time in conveniently incorporated into the expression for the longitude of the
subsolar point. It is not clear, however, who first derived the formula and, in addition, for lack
of documentation and publication, it has not been widely circulated. Coincidentally, Sproul
(2007) derived the said unit vector using vector analysis and obtained identically the same x-, y-
and z-components mentioned above; from there, however, the author did not proceed to use
the method discussed here.
The variables involved in deriving solar geometry can be put into two categories: 1) those that
fall within the area of astronomy and can be termed, appropriately, ephemerides, and the
relevant ones in this category are the declination of the Sun, the Earth-Sun distance, and the
equation of time; 2) those that purely belong to 3D geometry and/or spherical trigonometry,
and the ones in this category are solar zenith and azimuth angles and can be derived from those
in Category 1).
For first approximations, there is a simple formula for the declination of the Sun which neglects
the year-to-year change; the Earth-Sun distance is considered a constant, namely, 1 au; and the
equation of time is ignored. Since it is easy and straightforward to use those formulas in The
Astronomical Almanac, as has been done by Michalsky (1988), there is not a good reason to opt
for simpler ones with more uncertainties. In this note, we will first provide formulas from The
Astronomical Almanac for the Year 2019 for variables in Category 1), and then give formulas for
those in Category 2). To illustrate how these formulas work, we put some results in two figures.
Finally, our subroutine in Fortran 90 is put in Appendix A.
2 The Formulas
2.1 The declination of the Sun (𝜹), the Earth-Sun distance (𝑹), and the equation of time (𝑬)
2
The following formulas are straight from The Astronomical Almanac for the Year 2019 except
the time argument 𝑛 has been modified for an arbitrary year, preferably from 1950 to 2050,
and they are in the order such that results from earlier expressions can be used by later
expressions. Only those equations of immediate interest are numbered.
𝑛 = −1.5 + (𝑌𝑖𝑛 − 2000) ∙ 365 + 𝑁𝑙𝑒𝑎𝑝 + Day of Year + Fraction of Day from 0:00 UT (day),
𝐿 = 280.466 + 0.9856474𝑛 (°),
𝑔 = 357.528 + 0.9856003𝑛 (°),
𝜆 = 𝐿 + 1.915 sin 𝑔 + 0.020 sin(2𝑔) (°),
𝜀 = 23.440 − 0.0000004𝑛 (°);
𝛼 = tan−1(cos 𝜀 tan 𝜆) ∙ 180⁄𝜋 (),
𝛿 = sin−1(sin 𝜀 sin 𝜆) ∙ 180⁄𝜋 (), (1)
𝑅 = 1.00014 − 0.01671 cos 𝑔 − 0.00014 cos(2𝑔) (au), (2)
(𝐿
𝐸𝑚𝑖𝑛 = − 𝛼) ∙ 4 (min). (3)
where
𝑛 is the number of days of Terrestrial Time (TT) from J2000.0 UT;
𝑌𝑖𝑛 is the input year;
𝑁𝑙𝑒𝑎𝑝 is the number of leap years;
𝐿 is the mean longitude of the Sun corrected for aberration;
𝑔 is the mean anomaly;
𝜆 is the ecliptic longitude;
𝜀 is the obliquity of ecliptic;
𝛼 is the right ascension;
𝛿 is the declination of the Sun;
𝑅 is the Earth-Sun distance;
𝐸𝑚𝑖𝑛 is the equation of time.
Note that 𝐿 and 𝑔 as well as 𝜆 given as above can be either positive or negative, but
computationally they need to be put in the range 0 to 360, and this can be accomplished by
using the modulo function; 𝛼 needs to be in the same quadrant as 𝜆, and this can be done by
using the atan2 function, which takes two arguments, instead of the atan function, which
takes only one argument. All these treatments have been properly taken care of in the code in
Appendix A.
According to the Almanac, the errors of the right ascension and declination of the Sun given by
these formulas are less than (1/60), and the error of the equation of time is less than 3.5
seconds, if the input year is between 1950 and 2050.
Suppose the observer’s coordinates, or latitude and longitude, are (𝜙𝑜 , 𝜆𝑜 ), and the subsolar
point’s coordinates are (𝜙𝑠 , 𝜆𝑠 ), then the x-, y- and z-components of the unit vector, 𝑺, pointing
from the observer to the center of the Sun are as follows:
3
𝜙𝑠 = 𝛿, (4)
𝜆𝑠 = −15(𝑇𝐺𝑀𝑇 − 12 + 𝐸𝑚𝑖𝑛 /60), (5)
𝑆𝑥 = cos 𝜙𝑠 sin(𝜆𝑠 − 𝜆𝑜 ), (6)
𝑆𝑦 = cos 𝜙𝑜 sin 𝜙𝑠 − sin 𝜙𝑜 cos 𝜙𝑠 cos(𝜆𝑠 − 𝜆𝑜 ), (7)
𝑆𝑧 = sin 𝜙𝑜 sin 𝜙𝑠 + cos 𝜙𝑜 cos 𝜙𝑠 cos(𝜆𝑠 − 𝜆𝑜 ). (8)
It can be shown that there exists 𝑆𝑥2 + 𝑆𝑦2 + 𝑆𝑧2 = 1. Sproul (2007) used vector analysis to
derive the x-, y- and z-components of 𝑺, and they are exactly the same as the 𝑆𝑥 , 𝑆𝑦 and 𝑆𝑧
here, noticing that 𝜆𝑠 − 𝜆𝑜 differs from the hour angle, 𝜔, by only a negative sign.
𝑍 = cos−1 𝑆𝑧 , (9)
Eq. (10) gives an unambiguous solar azimuth angle and it is final, and it works everywhere from
pole to pole. In other words, the solar azimuth angle is in the right quadrant. The standard
atan2(y, x) function which follows the East-Clockwise convention is available in
programming/scripting languages Fortran, Python, etc. and it gives the angle in the range [-𝜋,
𝜋] which can be converted to [-180°, 180°].
The North-Clockwise convention can be achieved using 𝛾𝑠 = atan2(𝑆𝑥 , 𝑆𝑦 ), and the East-
Counterclockwise convention can be realized using 𝛾𝑠 =atan2(𝑆𝑦, 𝑆𝑥 ), though the latter is
rarely used in solar energy analysis.
The advantage of Eq. (10) is that it is not only concise, but never fails. When both 𝑆𝑥 and 𝑆𝑦 are
0, namely, when the subsolar point and the observer’s point are the same and, therefore, the
azimuth angle is not defined, Eq. (10) gives 0 and keeps the job running. This treatment is
physically inconsequential, because the term involving azimuth angles in solar energy analysis
also becomes 0.
The subsolar point is not an unfamiliar concept, but the way it is used as in the method
discussed here dispels some of the mysterious aura around solar geometry, and the Earth-Sun
configuration is thus mentally more accessible.
It can be easily shown that 𝑆𝑦 ⁄√𝑆𝑥2 + 𝑆𝑦2 , 𝑆𝑥 ⁄√𝑆𝑥2 + 𝑆𝑦2 and 𝑆𝑦 ⁄𝑆𝑥 are equivalent to the three
staple formulas traditionally used, namely, the sine, cosine and tangent of the azimuth angle,
respectively. Both the signs of 𝑆𝑥 and 𝑆𝑦 are required to determine the azimuth angle, but each
of the three formulas causes two possible distinct cases degenerate into one, which is why
4
none alone can give an unambiguous result. Sproul (2007) derived the expressions of 𝑆𝑥 , 𝑆𝑦 and
𝑆𝑧 using vector analysis, but did not use Eq. (10) to compute the solar azimuth angle; rather, the
author proceeded to discuss the three traditionally formulas at length.
Note these formulas are based on geocentric latitudes and no correction for the atmospheric
refraction has been applied to the solar zenith angle, 𝑍. The atmospheric refraction depends on
the temperature profile of the atmosphere and surface elevation and can be evaluated later.
Note that the equation of time, 𝐸𝑚𝑖𝑛 , appears in the expression for 𝜆𝑠 , the longitude of the
subsolar point.
A word of warning is that in computer languages, the input angles of trigonometric functions
and output angles of inverse trigonometric functions are all in radians.
Finally, Eq. (10) is not limited to the computer. The idea behind it is applicable even when one
uses a calculator, and it can be done as follows: 1) Calculate the values of 𝑆𝑥 and 𝑆𝑦 ; 2)
Determine which quadrant the angle falls in by inspecting the signs of 𝑆𝑥 and 𝑆𝑦 ; 3) If the angle
is in the 1st and 4th quadrants, 𝛾𝑠 = tan−1(𝑆𝑦 ⁄𝑆𝑥 ); otherwise, 𝛾𝑠 = tan−1(𝑆𝑦 ⁄𝑆𝑥 ) + 180,
supposing the calculator is in the degree mode.
In last section, it has been presumed that the Sun is a body with an altitude of infinity. In the
case of a satellite with a finite altitude, 𝐻, it can be shown that Eqs. (6)-(10) can still be used,
assuming now that (𝜙𝑠 , 𝜆𝑠 ) are the coordinates of the sub-satellite point and known, except an
Δ𝑍𝐻 needs to be added to the 𝑍 from Eq. (9) and, Δ𝑍𝐻 is as follows
𝑅 sin 𝑍
∆𝑍𝐻 =tan−1[𝑅(1−cos 𝑍)+𝐻], (11)
where 𝑅 is the radius of the Earth, assuming a spherical Earth, and 𝐻 is the altitude of the
satellite. The zenith angle of the satellite is thus 𝑍 + ∆𝑍𝐻 . Note that when 𝐻 is infinity, ∆𝑍𝐻 =
0.
For completeness, the x-, y- and z-components of the unit vector originating from the observer
and pointing toward the satellite are
sin(𝑍+∆𝑍𝐻 )
𝑆𝑥𝑠𝑎𝑡 = 𝑆𝑥 , (12)
sin 𝑍
sin(𝑍+∆𝑍𝐻 )
𝑆𝑦𝑠𝑎𝑡 = 𝑆𝑦 , (13)
sin 𝑍
cos(𝑍+∆𝑍𝐻 )
𝑆𝑧𝑠𝑎𝑡 = 𝑆𝑧 , (14)
cos 𝑍
where 𝑆𝑥 , 𝑆𝑦 , 𝑆𝑧 and 𝑍 are from Eqs. (6)-(9), respectively, assuming that that (𝜙𝑠 , 𝜆𝑠 ) are the
coordinates of the sub-satellite point and known. And the azimuth angle of the satellite is
5
𝛾𝑠𝑎𝑡 =atan2(−𝑆𝑥𝑠𝑎𝑡 , −𝑆𝑦𝑠𝑎𝑡 ). (15)
Since 𝑆𝑥𝑠𝑎𝑡 and 𝑆𝑦𝑠𝑎𝑡 in Eq. (15) differ from 𝑆𝑥 and 𝑆𝑦 in Eq. (10) by the same factor, they give the
same result.
2.4 When the observer is a satellite and the observed body is the Sun
Now assume that the coordinates of the sub-satellite point and the subsolar point are (𝜙𝑜 , 𝜆𝑜 )
and (𝜙𝑠 , 𝜆𝑠 ), respectively, Eqs. (6)-(10) can be used for the solar zenith angle and solar azimuth
angle from the perspective of the satellite, assuming the satellite uses the terrestrial
𝜋
convention for directions. The exception is that the solar zenith angle at sunset is now 2 +
𝑅
cos−1 ( ), where 𝑅 is the radius of the Earth, assuming a spherical Earth, and 𝐻 is the
𝑅+𝐻
altitude of the satellite. In the case of a surface-based observer, 𝐻 = 0, and the solar zenith
𝜋
angle at sunset is simply 2 in the absence of the atmospheric refraction.
3 Sample Results
Shown in Fig. 1a and 1b are the declination of the Sun, 𝛿, the solar constant factor, 1/𝑅 2 , and
the equation of time, 𝐸𝑚𝑖𝑛 for the year 2020 at 1-day step. These are directly from the The
Astronomical Almanac for the Year 2019.
Fig. 1c shows the annual path of the subsolar point at GMT hours 8:00 to 13:00 at 1-hour
interval in the year 2020. The “8” figures are due to the equation of time. Fig. 1d shows the x-
and y-components of the unit vector, S, at a site in the US. The rightmost “8” figure gets
distorted the most, because the corresponding hour is the farthest from the local noon, and
because these “8” figures are actually the horizontal projections of the analemmas shown in
Fig. 2.
Fig. 2 shows the x-, y- and z-components of the unit vector, S, throughout the year 2020 at 1-
hour step at the same site as in Fig. 1c and 1d. This is a complete depiction of the position of
the Sun for an entire year, because the z-component determines the solar zenith angle and the
x- and y-components determine the solar azimuth angle. As the vector, S, moves in time, its tip
traces out the familiar “8” figures, and these figures are literally the analemmas that can be
observed in the celestial sphere. This type of figure can be generated for any given location, so
that the Sun’s position gets visualized in practically the whole domain of time.
4 Summary
This note presented a solar azimuth angle formula derived from a somewhat different
perspective. The result is an algorithm that is conceptually more concise and computationally
much simpler than the three traditional formulas, yet the algorithm has the same mathematical
6
rigor and accuracy as any of the three traditional formulas. This algorithm also leads to better
visualization of the annual excursion of the Sun’s position for any given terrestrial location.
Acknowledgments
This work is part of the Prediction Of Worldwide Energy Resources (POWER) Project funded
through the NASA Earth Science/Applied Science Program.
References
The Astronomical Almanac for the Year 2019. The United States Naval Observatory.
Bhatia, S.C., 2014. Advanced Renewable Energy Systems, Part I. Woodhead Publishing India Pvt.
Ltd.
Michalsky, J.J., 1988. The Astronomical Almanac’s Algorithm for Approximate Solar Position
(1950-2050). Sol Energy, 40(3), 227-235.
Probst, O., 2002. The apparent motion of the Sun revisited. Eur. J. Phys. 23, 315–322.
Soulayman, S., 2018. Comments on solar azimuth angle. Renew Energ, 123, August 2018, 294-
300.
Sproul, A. B., 2007. Derivation of the solar geometric relationships using vector analysis.
Renewable Energy, 32, 1187-1205.
7
Fig. 1. a. The declination of the Sun, 𝛿, and the solar constant factor, 1/𝑅2 for the year 2020 at 1-day step; b. The equation of
time, 𝐸𝑚𝑖𝑛 , for the year 2020 in 1-day step; c. The track of the subsolar point at GMT 8:00, 9:00, 10:00, 11:00, 12:00 and 13:00
throughout the year 2020; d. The x- and y-components of the unit vector, 𝑆, at a site in the US site at GMT 14:34, 15:34, 16:34,
17:34, 18:34 (around local noon) and 19:34.
8
Fig. 2. Annual excursion of the unit vector S at 1-hour step throughout the year 2020 at a US site. Note that nighttime is in gray
color and occurs when 𝑆𝑧 < 0. Each figure “8” corresponds to the same hour and is literally an analemma in the celestial
sphere. The “8” figure at the lowest position represents the hour around local midnight, and the hour progresses
counterclockwise. Note that the color bar also applies to nighttime analemmas.
9
! solarz: solar zenith angle in deg;
! azi: solar azimuth in deg the range -180 to 180, South-Clockwise
! Convention.
!
! Note: The user may modify the code to output other variables.
implicit none
julday(0)=0
do i=1, 12
julday(i)=julday(i-1)+nday(i)
enddo
! Note: julday(12) is equal to either 365 or 366.
dyear=inyear-2000
dayofyr=julday(inmon-1)+inday
if(dyear<=0) then
xleap=int(real(dyear)/4) !xleap has the SAME SIGN as dyear. !!!
else
xleap=int(real(dyear)/4)+1 !Since 2000 is a leap year.
endif
10
PHIo=xlat*rpd
PHIs=sunlat*rpd
LAMo=xlon*rpd
LAMs=sunlon*rpd
Sx=cos(PHIs)*sin(LAMs-LAMo)
Sy=cos(PHIo)*sin(PHIs)-sin(PHIo)*cos(PHIs)*cos(LAMs-LAMo)
Sz=sin(PHIo)*sin(PHIs)+cos(PHIo)*cos(PHIs)*cos(LAMs-LAMo)
Endsubroutine sunpos_ultimate_azi_atan2
11