## Re: [mh] sun angle calculation

 Re: [mh] sun angle calculation From: Robvh - 2009-07-31 08:33:33 ```Hi Ralf The calculator you posted helped me out wonderfully but with the fixed offset of 1 hour it seems to be optimized for CET. It makes more sense to use the gmtime() function that returns UTC and add the longitude to generate the true solar time. I'm not an expert perl programmer so the accuray of the log message is rediculous, but you may get the drift: # Source: http://www.jgiesen.de/SME/tk/index.htm #declination = -23.45*cos(K*360*(yearday+10)/365) #true_time_to_noon = UTC_hour + UTC_minute/60 + longitude/15.0 - 12 #x = sin(K*latidute)*sin(K*declination) + cos(K*latidute)*cos(K*declination)*Math.cos(K*15*true_time_to_noon) #sunhight = x/K + 0.25*x*x*x/K (ARCSIN-approximated through polynom) use vars ('\$Solar_Elevation', '\$Solar_Azimuth'); if (\$New_Minute || \$Reload || \$Startup) { my (\$sec,\$minute,\$hour,\$mday,\$mon,\$year,\$wday,\$yday,\$isdst) = gmtime(); my \$true_time_to_noon = \$hour + \$minute / 60 + \$config_parms{longitude} / 15 - 12; my \$K = 0.01745; my \$declination = -23.45 * cos( \$K * 360 * (\$yday + 10) / 365); my \$x = sin(\$K * \$config_parms{latitude}) * sin(\$K * \$declination) + cos(\$K * \$config_parms{latitude}) * cos(\$K * \$declination) * cos(\$K*15*\$true_time_to_noon); \$Solar_Elevation = \$x/\$K + 0.25*\$x*\$x*\$x/\$K; my \$y = -(sin(\$K * \$config_parms{latitude}) *\$x - sin(\$K * \$declination)) / (cos(\$K * \$config_parms{latitude}) * sin(atan2(sqrt(1 - \$x * \$x), \$x))); \$Solar_Azimuth = atan2( sqrt(1- \$y * \$y), \$y) / \$K; \$Solar_Azimuth = 360 - \$Solar_Azimuth if (\$hour > 12); &main::print_log("Solar - Hours from apex: \$true_time_to_noon Elevation: \$Solar_Elevation Azimuth: \$Solar_Azimuth"); } # Solar_Azimuth is the direction of the sun (clockwise, 0 is north) # Solar_Elevation is the hight of the sun. (0 is half down the horizon) # To trigger actions I use the following vars: my \$Sun_SE = (\$Solar_Azimuth >= 95 && \$Solar_Azimuth <= 250 && \$Solar_Elevation >=30 && \$Solar_Elevation <=90) ? 1 : 0; my \$Sun_NE = (\$Solar_Azimuth >= 0 && \$Solar_Azimuth <= 130 && \$Solar_Elevation >=30 && \$Solar_Elevation <=90) ? 1 : 0; my \$Sun_NW = (\$Solar_Azimuth >= 275 && \$Solar_Azimuth <= 150 && \$Solar_Elevation >=30 && \$Solar_Elevation <=90) ? 1 : 0; -- View this message in context: http://www.nabble.com/sun-angle-calculation-tp22843513p24745657.html Sent from the Misterhouse - User mailing list archive at Nabble.com. ```

 Re: [mh] sun angle calculation From: Robvh - 2009-07-31 08:33:33 ```Hi Ralf The calculator you posted helped me out wonderfully but with the fixed offset of 1 hour it seems to be optimized for CET. It makes more sense to use the gmtime() function that returns UTC and add the longitude to generate the true solar time. I'm not an expert perl programmer so the accuray of the log message is rediculous, but you may get the drift: # Source: http://www.jgiesen.de/SME/tk/index.htm #declination = -23.45*cos(K*360*(yearday+10)/365) #true_time_to_noon = UTC_hour + UTC_minute/60 + longitude/15.0 - 12 #x = sin(K*latidute)*sin(K*declination) + cos(K*latidute)*cos(K*declination)*Math.cos(K*15*true_time_to_noon) #sunhight = x/K + 0.25*x*x*x/K (ARCSIN-approximated through polynom) use vars ('\$Solar_Elevation', '\$Solar_Azimuth'); if (\$New_Minute || \$Reload || \$Startup) { my (\$sec,\$minute,\$hour,\$mday,\$mon,\$year,\$wday,\$yday,\$isdst) = gmtime(); my \$true_time_to_noon = \$hour + \$minute / 60 + \$config_parms{longitude} / 15 - 12; my \$K = 0.01745; my \$declination = -23.45 * cos( \$K * 360 * (\$yday + 10) / 365); my \$x = sin(\$K * \$config_parms{latitude}) * sin(\$K * \$declination) + cos(\$K * \$config_parms{latitude}) * cos(\$K * \$declination) * cos(\$K*15*\$true_time_to_noon); \$Solar_Elevation = \$x/\$K + 0.25*\$x*\$x*\$x/\$K; my \$y = -(sin(\$K * \$config_parms{latitude}) *\$x - sin(\$K * \$declination)) / (cos(\$K * \$config_parms{latitude}) * sin(atan2(sqrt(1 - \$x * \$x), \$x))); \$Solar_Azimuth = atan2( sqrt(1- \$y * \$y), \$y) / \$K; \$Solar_Azimuth = 360 - \$Solar_Azimuth if (\$hour > 12); &main::print_log("Solar - Hours from apex: \$true_time_to_noon Elevation: \$Solar_Elevation Azimuth: \$Solar_Azimuth"); } # Solar_Azimuth is the direction of the sun (clockwise, 0 is north) # Solar_Elevation is the hight of the sun. (0 is half down the horizon) # To trigger actions I use the following vars: my \$Sun_SE = (\$Solar_Azimuth >= 95 && \$Solar_Azimuth <= 250 && \$Solar_Elevation >=30 && \$Solar_Elevation <=90) ? 1 : 0; my \$Sun_NE = (\$Solar_Azimuth >= 0 && \$Solar_Azimuth <= 130 && \$Solar_Elevation >=30 && \$Solar_Elevation <=90) ? 1 : 0; my \$Sun_NW = (\$Solar_Azimuth >= 275 && \$Solar_Azimuth <= 150 && \$Solar_Elevation >=30 && \$Solar_Elevation <=90) ? 1 : 0; -- View this message in context: http://www.nabble.com/sun-angle-calculation-tp22843513p24745657.html Sent from the Misterhouse - User mailing list archive at Nabble.com. ```