#include "house.h"
#include "rpp.h"
/*
* Copyright James Ashton, Syseng, RSISE, ANU, Australia, 1996/2/4
*
* Set a lighting direction for the Sun based on location and the time of
* year and day. This is a rough approximation only, ignoring such
* intricacies as the equation of time.
*
* latitude is in degrees: positive North; negative South.
* month is the time of year: January 1st is approx 1.0; June 15th about 6.5.
* hour is the time of day. Midnight is 0.0 and noon is 12.0.
*
* The surface of the is Earth parallel to the z=0 plane, i.e.
* Up is in the direction of the positive z axis.
* North is in the direction of the positive y axis.
* East is in the direction of the positive x axis.
*/
void
Sun(double latitude, double month, double hour)
{
double a, b, c;
double x, y, z;
a = sin((month - 9.7) / 6.0 * M_PI) * 0.41;
b = hour / 12.0 * M_PI;
c = latitude / 180.0 * M_PI;
x = cos(a) * sin(b);
y = -sin(a) * cos(c) + cos(a) * cos(b) * sin(c);
z = -sin(a) * sin(c) - cos(a) * cos(b) * cos(c);
if (z > 0.0)
{
Light(1.0, NAN);
Directional(x, y, z);
}
(void)fprintf(stderr, "Sun:\taltitude %3.0lf degrees\n",
atan2(z, hypot(x, y)) * 180.0 / M_PI);
(void)fprintf(stderr, "\tazimuth %4.0lf degrees\n",
180.0 + atan2(-x, -y) * 180.0 / M_PI);
}