JavaScript - 计算正午太阳高度
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript - 计算正午太阳高度相关的知识,希望对你有一定的参考价值。
1 /* 2 * 正午太阳高度计算代码 3 * 4 * NurtaySolarAltitude(所求纬度, 南北半球(N或S), 月, 日) 5 * 6 */ 7 function NurtaySolarAltitude(a, b, c, d) { 8 function e(a, b, c, d, e, f) { 9 var g = new Date(a, b - 1, c), 10 h = new Date(d, e - 1, f), 11 i = (g - h) / 864e5; 12 i = Math.abs(i); 13 return i; 14 } 15 function f(a) { 16 var b, c, d; 17 a = Math.abs(a); 18 b = Math.floor(a); 19 c = Math.floor(60 * (a - b)); 20 d = Math.round(3600 * (a - b) % 60); 21 return b + "°" + c + "‘" + d + ‘"‘; 22 } 23 function g(a) { 24 return -a; 25 } 26 function h(a, b, c) { 27 var d; 28 if ("N" == c) d = 90 - Math.abs(a - b); 29 if ("S" == c) d = 90 - Math.abs(a + b); 30 return d; 31 } 32 var i; 33 a = Math.abs(a); 34 c = Math.abs(c); 35 d = Math.abs(d); 36 if (3 == c && 21 == d || 9 == c && 23 == d) { 37 i = 0 38 }; 39 if (3 == c && d > 21 || c > 3 && c < 6 || 6 == c && d < 22) { 40 i = .25188917 * e(0, c, d, 0, "3", "21") 41 }; 42 if (6 == c && 22 == d) { 43 i = 23.43333333 44 }; 45 if (6 == c && d > 22 || c > 6 && c < 9 || 9 == c && d < 23) { 46 i = .25188917 * e(0, c, d, 0, "9", "23") 47 }; 48 if (9 == c && d > 23 || c > 9 && c < 12 || 12 == c && d < 22) { 49 i = g(.26041667 * e(0, c, d, 0, "9", "23")) 50 }; 51 if (12 == c && 22 == d) { 52 i = g(23.43333333) 53 }; 54 if (12 == c && d > 22) { 55 i = g(.26315789 * e(0, c, d, 1, "3", "21")) 56 }; 57 if (c < 3 || 3 == c && d < 21) { 58 i = g(.26315789 * e(0, c, d, 0, "3", "21")) 59 }; 60 return f(h(a, i, b)); 61 }