Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calcAzEl(output, T, localtime, latitude, longitude, zone)
- {
- var eqTime = calcEquationOfTime(T)
- var theta = calcSunDeclination(T)
- if (output) {
- document.getElementById("eqtbox").value = Math.floor(eqTime*100 +0.5)/100.0
- document.getElementById("sdbox").value = Math.floor(theta*100+0.5)/100.0
- }
- var solarTimeFix = eqTime + 4.0 * longitude - 60.0 * zone
- var earthRadVec = calcSunRadVector(T)
- var trueSolarTime = localtime + solarTimeFix
- while (trueSolarTime > 1440)
- {
- trueSolarTime -= 1440
- }
- var hourAngle = trueSolarTime / 4.0 - 180.0;
- if (hourAngle < -180)
- {
- hourAngle += 360.0
- }
- var haRad = degToRad(hourAngle)
- var csz = Math.sin(degToRad(latitude)) * Math.sin(degToRad(theta)) + Math.cos(degToRad(latitude)) * Math.cos(degToRad(theta)) * Math.cos(haRad)
- if (csz > 1.0)
- {
- csz = 1.0
- } else if (csz < -1.0)
- {
- csz = -1.0
- }
- var zenith = radToDeg(Math.acos(csz))
- var azDenom = ( Math.cos(degToRad(latitude)) * Math.sin(degToRad(zenith)) )
- if (Math.abs(azDenom) > 0.001) {
- azRad = (( Math.sin(degToRad(latitude)) * Math.cos(degToRad(zenith)) ) - Math.sin(degToRad(theta))) / azDenom
- if (Math.abs(azRad) > 1.0) {
- if (azRad < 0) {
- azRad = -1.0
- } else {
- azRad = 1.0
- }
- }
- var azimuth = 180.0 - radToDeg(Math.acos(azRad))
- if (hourAngle > 0.0) {
- azimuth = -azimuth
- }
- } else {
- if (latitude > 0.0) {
- azimuth = 180.0
- } else {
- azimuth = 0.0
- }
- }
- if (azimuth < 0.0) {
- azimuth += 360.0
- }
- var exoatmElevation = 90.0 - zenith
- // Atmospheric Refraction correction
- if (exoatmElevation > 85.0) {
- var refractionCorrection = 0.0;
- } else {
- var te = Math.tan (degToRad(exoatmElevation));
- if (exoatmElevation > 5.0) {
- var refractionCorrection = 58.1 / te - 0.07 / (te*te*te) + 0.000086 / (te*te*te*te*te);
- } else if (exoatmElevation > -0.575) {
- var refractionCorrection = 1735.0 + exoatmElevation * (-518.2 + exoatmElevation * (103.4 + exoatmElevation * (-12.79 + exoatmElevation * 0.711) ) );
- } else {
- var refractionCorrection = -20.774 / te;
- }
- refractionCorrection = refractionCorrection / 3600.0;
- }
- var solarZen = zenith - refractionCorrection;
- if ((output) && (solarZen > 108.0) ) {
- document.getElementById("azbox").value = "dark"
- document.getElementById("elbox").value = "dark"
- } else if (output) {
- document.getElementById("azbox").value = Math.floor(azimuth*100 +0.5)/100.0
- document.getElementById("elbox").value = Math.floor((90.0-solarZen)*100+0.5)/100.0
- if (document.getElementById("showae").checked) {
- showLineGeodesic2("azimuth", "#ffff00", azimuth)
- }
- }
- return (azimuth)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement