Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. function calcAzEl(output, T, localtime, latitude, longitude, zone)
  2. {
  3. var eqTime = calcEquationOfTime(T)
  4. var theta = calcSunDeclination(T)
  5. if (output) {
  6. document.getElementById("eqtbox").value = Math.floor(eqTime*100 +0.5)/100.0
  7. document.getElementById("sdbox").value = Math.floor(theta*100+0.5)/100.0
  8. }
  9. var solarTimeFix = eqTime + 4.0 * longitude - 60.0 * zone
  10. var earthRadVec = calcSunRadVector(T)
  11. var trueSolarTime = localtime + solarTimeFix
  12. while (trueSolarTime > 1440)
  13. {
  14. trueSolarTime -= 1440
  15. }
  16. var hourAngle = trueSolarTime / 4.0 - 180.0;
  17. if (hourAngle < -180)
  18. {
  19. hourAngle += 360.0
  20. }
  21. var haRad = degToRad(hourAngle)
  22. var csz = Math.sin(degToRad(latitude)) * Math.sin(degToRad(theta)) + Math.cos(degToRad(latitude)) * Math.cos(degToRad(theta)) * Math.cos(haRad)
  23. if (csz > 1.0)
  24. {
  25. csz = 1.0
  26. } else if (csz < -1.0)
  27. {
  28. csz = -1.0
  29. }
  30. var zenith = radToDeg(Math.acos(csz))
  31. var azDenom = ( Math.cos(degToRad(latitude)) * Math.sin(degToRad(zenith)) )
  32. if (Math.abs(azDenom) > 0.001) {
  33. azRad = (( Math.sin(degToRad(latitude)) * Math.cos(degToRad(zenith)) ) - Math.sin(degToRad(theta))) / azDenom
  34. if (Math.abs(azRad) > 1.0) {
  35. if (azRad < 0) {
  36. azRad = -1.0
  37. } else {
  38. azRad = 1.0
  39. }
  40. }
  41. var azimuth = 180.0 - radToDeg(Math.acos(azRad))
  42. if (hourAngle > 0.0) {
  43. azimuth = -azimuth
  44. }
  45. } else {
  46. if (latitude > 0.0) {
  47. azimuth = 180.0
  48. } else {
  49. azimuth = 0.0
  50. }
  51. }
  52. if (azimuth < 0.0) {
  53. azimuth += 360.0
  54. }
  55. var exoatmElevation = 90.0 - zenith
  56.  
  57. // Atmospheric Refraction correction
  58.  
  59. if (exoatmElevation > 85.0) {
  60. var refractionCorrection = 0.0;
  61. } else {
  62. var te = Math.tan (degToRad(exoatmElevation));
  63. if (exoatmElevation > 5.0) {
  64. var refractionCorrection = 58.1 / te - 0.07 / (te*te*te) + 0.000086 / (te*te*te*te*te);
  65. } else if (exoatmElevation > -0.575) {
  66. var refractionCorrection = 1735.0 + exoatmElevation * (-518.2 + exoatmElevation * (103.4 + exoatmElevation * (-12.79 + exoatmElevation * 0.711) ) );
  67. } else {
  68. var refractionCorrection = -20.774 / te;
  69. }
  70. refractionCorrection = refractionCorrection / 3600.0;
  71. }
  72.  
  73. var solarZen = zenith - refractionCorrection;
  74.  
  75. if ((output) && (solarZen > 108.0) ) {
  76. document.getElementById("azbox").value = "dark"
  77. document.getElementById("elbox").value = "dark"
  78. } else if (output) {
  79. document.getElementById("azbox").value = Math.floor(azimuth*100 +0.5)/100.0
  80. document.getElementById("elbox").value = Math.floor((90.0-solarZen)*100+0.5)/100.0
  81. if (document.getElementById("showae").checked) {
  82. showLineGeodesic2("azimuth", "#ffff00", azimuth)
  83. }
  84. }
  85. return (azimuth)
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement