Wikipedia cita esta fórmula para calcular el azimut solar:
Dónde:
Estoy implementando esta ecuación en JavaScript, pero no parece correcta. ¿Puede alguien aquí ayudarme a confirmar si esta ecuación es correcta o no?
Aquí está mi implementación de JS. Lo único extraño está al final: limitar el dominio acos a [-1, 1] para evitar valores de NaN.
const getSolarAzimuth = function(
zenithAngle, hourAngle, declination, latitude
) {
const cos = Math.cos;
const sin = Math.sin;
const cos_phi = (
sin(declination) * cos(latitude) - cos(hourAngle) * cos(declination) *
sin(latitude)) /
sin(zenithAngle);
return Math.acos(Math.min(Math.max(cos_phi, -1), 1));
};
He confirmado que esta fórmula es correcta. Tenía las unidades incorrectas en el código, que @Glorfindel sugirió: el ángulo horario del sol estaba en horas en lugar de radianes.
Necesitaba ajustar el desplazamiento del ángulo del acimut en función del ángulo de la hora:
// The angle offset needs to be adjusted based on whether the hour angle
// is in the morning or the evening.
// https://en.wikipedia.org/wiki/Solar_azimuth_angle#Formulas
if (hourAngle < 0 || hourAngle > Math.PI) {
return az;
}
return (Math.PI * 2) - az;
Glorfindel
nyby
tosico