Sun position
Sun position algorithm
sun.h
Go to the documentation of this file.
1 #ifndef SUN_H
2 #define SUN_H
3 /*============================================================================*/
4 /*!\file
5  * \brief sun.h - routines to calculate the Sun's position
6  *
7  * \author David Hoadley
8  *
9  * \details
10  * Alternative routines which calculate the sun's position with differing
11  * levels of accuracy. The alternatives are
12  * - a low precision routine, taken from the _Astronomical Almanac_
13  * - a much more detailed, high precision routine, based on the Solar
14  * Position Algorithm, as published by the National Renewable Energy
15  * Laboratory (referred to as the NREL SPA throughout this software)
16  *
17  * Rectangular coordinates are used wherever possible, to minimise the
18  * unnecessary recalculation of trigonometric functions.
19  *
20  * \par References:
21  * The _Astronomical Almanac_, 2007, page C24\n
22  * Reda, Ibrahim and Andreas, Afshin,
23  * _Solar Position Algorithm for Solar Radiation Applications._
24  * National Renewable Energy Laboratory publication no. NREL/TP-560-34302,
25  * June 2003, revised 2008.
26  *
27  *==============================================================================
28  */
29 /*
30  * Copyright (c) 2020, David Hoadley <vcrumble@westnet.com.au>
31  * All rights reserved.
32  *
33  * Redistribution and use in source and binary forms, with or without
34  * modification, are permitted provided that the following conditions are met:
35  *
36  * * Redistributions of source code must retain the above copyright notice, this
37  * list of conditions and the following disclaimer.
38  * * Redistributions in binary form must reproduce the above copyright notice,
39  * this list of conditions and the following disclaimer in the documentation
40  * and/or other materials provided with the distribution.
41  *
42  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
46  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52  * POSSIBILITY OF SUCH DAMAGE.
53  */
54 #include "sky.h"
55 #include "sky0.h"
56 #include "vectors3d.h"
57 
58 /*
59  * Global #defines and typedefs
60  */
61 
62 
63 /*
64  * Global functions available to be called by other modules
65  */
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
70 void sun_aaApparentApprox(double n,
71  V3D_Vector *appV,
72  double *dist_au);
73 
74 void sun_nrelApp2(double t_cy,
75  const Sky0_Nut1980 *nut,
76  V3D_Vector *appV,
77  double *dist_au);
78 void sun_nrelApparent(double j2kTT_cy, Sky_TrueEquatorial *pos);
79 void sun_nrelTopocentric(double j2kUtc_d,
80  const Sky_DeltaTs *deltas,
81  const Sky_SiteProp *site,
82  Sky_SiteHorizon *topo);
83 
84 double sun_solarNoon(int year,
85  int month,
86  int day,
87  const Sky_DeltaTs *deltas,
88  const Sky_SiteProp *site,
89  Sky_SiteHorizon *topo);
90 double sun_riseSet(int year,
91  int month,
92  int day,
93  bool getSunrise,
94  const Sky_DeltaTs *deltas,
95  const Sky_SiteProp *site,
96  Sky_SiteHorizon *topo);
97 
98 /*
99  * Global variables accessible by other modules
100  */
101 /* (none) */
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #endif /*SUN_H*/
Sky_DeltaTs
This structure contains relatively constant data, and is set up by one of the three functions sky_ini...
Definition: sky.h:166
sun_nrelApp2
void sun_nrelApp2(double t_cy, const Sky0_Nut1980 *nut, V3D_Vector *appV, double *dist_au)
This function calculates the Sun position in apparent coordinates, using the NREL SPA algorithm (see ...
Definition: sun.c:148
Sky_TrueEquatorial
Struct used for holding an object's coordinates in equatorial apparent or Intermediate coordinates.
Definition: sky.h:106
sun_nrelTopocentric
void sun_nrelTopocentric(double j2kUtc_d, const Sky_DeltaTs *deltas, const Sky_SiteProp *site, Sky_SiteHorizon *topo)
Calls sun_nrelApparent() to calculate the Sun's position in apparent coordinates using the NREL Sun P...
Definition: sun.c:266
Sky_SiteProp
Site properties.
Definition: sky.h:315
sun_aaApparentApprox
void sun_aaApparentApprox(double n, V3D_Vector *appV, double *dist_au)
This function calculates an approximate Sun position in apparent coordinates using the algorithm give...
Definition: sun.c:105
V3D_Vector
3x1 vector.
Definition: vectors3d.h:57
sun_riseSet
double sun_riseSet(int year, int month, int day, bool getSunrise, const Sky_DeltaTs *deltas, const Sky_SiteProp *site, Sky_SiteHorizon *topo)
Routine to calculate the time of sunrise or sunset for the day specified by year, month and day.
Definition: sun.c:363
Sky0_Nut1980
Nutation angles and obliquity.
Definition: sky0.h:73
sky.h
sky.h - structures and routines for astronomical observing & tracking
vectors3d.h
vectors3d.h - Three dimensional geometry, vectors and matrices
sun_nrelApparent
void sun_nrelApparent(double j2kTT_cy, Sky_TrueEquatorial *pos)
Calculate the Sun's position as a unit vector and a distance, in apparent coordinates.
Definition: sun.c:211
sun_solarNoon
double sun_solarNoon(int year, int month, int day, const Sky_DeltaTs *deltas, const Sky_SiteProp *site, Sky_SiteHorizon *topo)
Routine to calculate the time of solar noon (Sun transit) for the day specified by year,...
Definition: sun.c:310
sky0.h
sky0.h - astronomical coordinate conversion for NREL Sun Position Algorithm
Sky_SiteHorizon
Coordinates of a celestial object in the horizon frame, in both rectangular and polar forms.
Definition: sky.h:129