# Sun elevation

## Recommended Posts

The sun elevation angle is the angle of the sun over the local horizon at a certain time.Assumed is spring begin at the 80th day of year (21 March) and an average yearlength of 365.25 days. Individual year lengths and spring shifts are neglected. In first order approximation the earth orbit is circular.To get the local "sun" time, GMT and the longitude is needed:localsuntime=zulutime+longitude*24/360=zulutime+longitude/15The "real" local time can't be used, because of the timezones that attach the same time for a whole stretch of longitudes (ideal 15

##### Share on other sites
 Help AVSIM continue to serve you!Please donate today!

In principle it is:%( (* zulutime+longitude/15 *)(P:ZULU TIME,hours) (A:PLANE LONGITUDE, degrees) 15 / + (* (7.3*sin((dayofyear-3)/365.25*360) *)(P:ZULU DAY OF YEAR,number) 3 - 365.25 / 2.0 pi * * sin 7.3 * (* -9.8*sin((dayofyear-80)/365.25*720)) *)(P:ZULU DAY OF YEAR,number) 80 - 365.25 / 4.0 pi * * sin -9.8 * + 60 / - (>L:local_sun_time,number) (* 23.5*sin((dayofyear-80)/365.25*360) *)(P:ZULU DAY OF YEAR,number) 80 - 365.25 / 2.0 pi * * sin 23.5 *(* (abs(lat)-90)*cos(localsuntime/24*360) *)(L:local_sun_time,number) 24.0 / 2.0 pi * * cos90 (A:PLANE LATITUDE, degrees) abs - *(A:PLANE LATITUDE, degrees) 0 > if{ - } els{ + }(>L:local_sun_angle,number)(L:local_sun_angle,number))%!.4f!but I have my doubts, if FS does handle it this way. There are differences at about +- 3

##### Share on other sites

Sheesh! :)Thanks Arne... I'll have to digest this awhile before moving forward. Hopefully FS2k2 will be able to 'calculate' this quicker that it took to type it it!I'll have to try this in a gauge and then see if the calculated L:local_sun_angle,number will be useful as a trigger for a boolean operation.BillAVSIM OmbudsmanFounder and Director,Creative Recycling of Aircraft Partshttp://mtco.com/~rsam/fartslogo.jpg

##### Share on other sites

Makes good sense, Arne. Thanks for taking the time.

##### Share on other sites

Arne,Question:What does ** mean?, cuadratic equation? (like x2)Jan"Procul Negotiis"

##### Share on other sites

No it doesn't. You can use sqr for this. The two * * are two seperate multiplication, one after the other.BTW. my results are not really good. I have to think about it again, maybe it's wrong to apply the eccentric approximation, which is astronomically correct for the shift of the midday line, to the dusk/dawn time. Or I'm totally wrong. Or MS's astronomy differs from real world, I don't know.Arne Bartels

##### Share on other sites

I guess Microsoft atronomy differs from real world in that the earth is a cylinder instead of a sphere :) Not sure though, but it seems to be this way due to the massive rendering errors close to the poles, although the starmap doesn't seem to suffer this problem; the north star is where it is supposed to be :DEarth orbit eccentricity and earth radius variation I think is not significant in this calculation.Thanks for the formulas, I now know in which direction to look, my earlier attempts where, err, somewhat different :)

##### Share on other sites

Hi,Tested it at several places and times, it looks good.Using:(L:local_sun_angle,number).> if{ (>K:.) }works of course.(I put the big formulas elsewhere)Jan"Procul Negotiis"

##### Share on other sites

>Tested it at several places and times, it looks good.>Using:>>(L:local_sun_angle,number).> if{ (>K:.) }>>works of course.>>(I put the big formulas elsewhere)Jan, could you post the .xml as an attachment, or send it to me at n4gix@attbi.com?I simply don't have enough time to figure out why I cannot get anthing other than 51.0502 to display... :)I just need something that will toggle a K_Event on/off approximately at sunrise and sunset...TIABillAVSIM OmbudsmanFounder and Director,Creative Recycling of Aircraft Partshttp://mtco.com/~rsam/fartslogo.jpg

##### Share on other sites

Frather,Here it is, but all credits to Arne.The first one i have put in a "store-file" with other difficult formulas. (P:ZULU TIME,hours) (A:PLANE LONGITUDE, degrees) 15 / + (P:ZULU DAY OF YEAR,number) 3 - 365.25 / 2.0 pi * * sin 7.3 *(P:ZULU DAY OF YEAR,number) 80 - 365.25 / 4.0 pi * * sin -9.8 * + 60 / - (>L:local_sun_time,number) (P:ZULU DAY OF YEAR,number) 80 - 365.25 / 2.0 pi * * sin 23.5 *(L:local_sun_time,number) 24.0 / 2.0 pi * * cos90 (A:PLANE LATITUDE, degrees) abs - *(A:PLANE LATITUDE, degrees) 0 > if{ - } els{ + }(>L:local_sun_angle,number)The last one you can use anywhere as an invisible gauge.(L:local_sun_angle,number) 10 < (A:Anything etc.) && if{ (>K:Anything etc.) }I think _ON, _OFF ans _SET commands works best.Jan"Procul Negotiis"

##### Share on other sites

Thank you Jan and Arne!Part of the problem I had was splicing the formula back together to eliminate the "carriage returns" and eliminate thepesky 'spaces' that seem to creep into the formula at unexpected places... :)Now I have a nice little 'counter' displaying on a test gauge that is busy reporting the results of the calculation in 'real time.' When I get back from \$job this afternoon I'll set up the 'autoswitch' I need to control the 'daytime' 3d panel lighting. It will be so nice to have a brightly illuminated 3d panel that won't be so drastically affected by the sun's relative position to the a/c's position.MS seems to have grossly "overmodeled" the shading effects of the sun's position in the 3d cockpit, and fx lighting will overcome this fault. This 'autoswitch' will eliminate the need for the pilot to turn the fx OFF manually. It is really TOO bright at night and destroys the carefully crafted panel lighting already developed. :)It didn't have to be "perfect;" simply consistent and approximate is good enough!BillAVSIM OmbudsmanFounder and Director,Creative Recycling of Aircraft Partshttp://mtco.com/~rsam/fartslogo.jpg

##### Share on other sites

Perhaps I'm just too slow to figure this out (or else too tired!), but I cannot seem to get this to work as I need it to... The problem is with the last statement. If I set the conditional to = 10, the K_Event will not be triggered because the calculated value is never EXACTLY equal to 10.If I set the conditional to < 10, then the K_Event will be continuously triggered on/off!!!How can I specify that I only want the K_Event to trigger ONCE each time the L:local_sun_angle is less than X degrees?Do I need to set G:Var1 and check for both conditions?In other words, if L:local_sun_angle,number < 10 AND G:Var1,bool == 1, THEN (>K:TOGGLE_XXX) (>G:Var1) ??? (P:ZULU TIME,hours) (A:PLANE LONGITUDE,degrees) 15 / + (P:ZULU DAY OF YEAR,number) 3 - 365.25 / 2.0 pi * * sin 7.3 * (P:ZULU DAY OF YEAR,number) 80 - 365.25 / 4.0 pi * * sin -9.8 * + 60 / - (>L:local_sun_time,number) (P:ZULU DAY OF YEAR,number) 80 - 365.25 / 2.0 pi * * sin 23.5 * (L:local_sun_time,number) 24.0 / 2.0 pi * * cos 90 (A:PLANE LATITUDE, degrees) abs - * (A:PLANE LATITUDE, degrees) 0 > if{ - }els{ + }(>L:local_sun_angle,number) %(L:local_sun_angle,number)%!.4f!(L:local_sun_angle,number) 10 == if{ (>K:PANEL_LIGHTS_TOGGLE) 0 (>K:TOGGLE_AFTERBURNER1) }BillAVSIM OmbudsmanFounder and Director,Creative Recycling of Aircraft Partshttp://mtco.com/~rsam/fartslogo.jpg

##### Share on other sites

Frather Bill,Hope you had a good night sleep, i didn't because of my job.I use this one and i shall explain, what happens.(L:panellights,bool) 0 == (L:local_sun_angle,number) 10 < && if{ (L:panellights,bool) ! (>L:panellights,bool) }(L:panellights,bool) 1 == (L:local_sun_angle,number) 10 > && if{ (L:panellights,bool) ! (>L:panellights,bool) }There is a switch in the panel (L:panellights,bool).When (L:local_sun_angle,number) is > 10 (other numbers as well) the switch automaticaly goes off.When (L:local_sun_angle,number) is < 10 the switch automaticaly comes on, independant of her position (on/off), but it is not possible to switch it manually. I think i have to work on that.Adding another variable (L:auto,bool) works ok, but i don't need that one.May be you can do something with this.Jan"Procul Negotiis"

##### Share on other sites

>Frather Bill,>>Hope you had a good night sleep, i didn't because of my job.>I use this one and i shall explain, what happens.Jan, I fully understand how it is *supposed* to work, yet the fact remains that it will not work here for some strange and inexplicable reason! :( (P:ZULU TIME,hours) (A:PLANE LONGITUDE,degrees) 15 / + (P:ZULU DAY OF YEAR,number) 3 - 365.25 / 2.0 pi * * sin 7.3 * (P:ZULU DAY OF YEAR,number) 80 - 365.25 / 4.0 pi * * sin -9.8 * + 60 / - (>L:local_sun_time,number) (P:ZULU DAY OF YEAR,number) 80 - 365.25 / 2.0 pi * * sin 23.5 * (L:local_sun_time,number) 24.0 / 2.0 pi * * cos 90 (A:PLANE LATITUDE, degrees) abs - * (A:PLANE LATITUDE, degrees) 0 > if{ - }els{ + }(>L:local_sun_angle) %(L:local_sun_angle, number)%!.4f!(A:Light Nav, bool) 1 == (L:local_sun_angle, number) 10 < && if{ (K:TOGGLE_NAV_LIGHTS) ! (>K:TOGGLE_NAV_LIGHTS) } (A:Light Nav, bool) 0 == (L:local_sun_angle, number) 10 > && if{ (K:TOGGLE_NAV_LIGHTS) ! (>K:TOGGLE_NAV_LIGHTS) }I can SEE the bloody variable L:local_sun_angle, number) counting downwards, yet when it passes 10, nothing happens!What DOES HAPPEN is that the Nav lights are locked ON, and do not toggle OFF whenever L:local_sun_angle, number is less than 10, which simply tells me that for some reason the computed value is NOT changing in the statement, even though it IS clearly changing in the function's display... BillAVSIM OmbudsmanFounder and Director,Creative Recycling of Aircraft Partshttp://mtco.com/~rsam/fartslogo.jpg

##### Share on other sites

OK, another test has proven that there is still something terribly wrong with my formula.I created another small display gauge that does nothing more than display the L:local_sun_angle, number variable, and it is reporting all ZEROS... Clearly then, there is a syntax error in this formula, but I'll be darned if I can spot it! :( (P:ZULU TIME,hours) (A:PLANE LONGITUDE,degrees) 15 / + (P:ZULU DAY OF YEAR,number) 3 - 365.25 / 2.0 pi * * sin 7.3 * (P:ZULU DAY OF YEAR,number) 80 - 365.25 / 4.0 pi * * sin -9.8 * + 60 / - (>L:local_sun_time,number) (P:ZULU DAY OF YEAR,number) 80 - 365.25 / 2.0 pi * * sin 23.5 * (L:local_sun_time,number) 24.0 / 2.0 pi * * cos 90 (A:PLANE LATITUDE, degrees) abs - * (A:PLANE LATITUDE, degrees) 0 > if{ - }els{ + }(>L:local_sun_angle) As I've said, I have the display in the 'main gauge' working and it *does* display a countdown/up of angles from 0 to 90 degrees, but for some reason that I cannot find is not actually assigning the value to the L: variable.BTW, it makes no difference whatever if I use (>L:local_sun_angle,number) or simply (>L:local_sun_angle) in the formula.BillAVSIM OmbudsmanFounder and Director,Creative Recycling of Aircraft Partshttp://mtco.com/~rsam/fartslogo.jpg

##### Share on other sites

Frather,I tested your gauge and the following happened:Sunangle < 10 : Nav lights Off, Sunangle > 10 : Nav lights On.In both positions it was impossible to use the Nav Lights Switch.(i did mention that earlier)I use:%((L:local_sun_angle,number))%!d!.Also noticed your 0.0000 value!It must be the synthax, cause mine showed -41 (other side of the earth?); perhaps distances between the characters are important.The next snip is an unaltered copy of my functioning formula. (P:ZULU TIME,hours) (A:PLANE LONGITUDE, degrees) 15 / + (P:ZULU DAY OF YEAR,number) 3 - 365.25 / 2.0 pi * * sin 7.3 *(P:ZULU DAY OF YEAR,number) 80 - 365.25 / 4.0 pi * * sin -9.8 * + 60 / - (>L:local_sun_time,number) (P:ZULU DAY OF YEAR,number) 80 - 365.25 / 2.0 pi * * sin 23.5 *(L:local_sun_time,number) 24.0 / 2.0 pi * * cos90 (A:PLANE LATITUDE, degrees) abs - *(A:PLANE LATITUDE, degrees) 0 > if{ - } els{ + }(>L:local_sun_angle,number)%((L:local_sun_angle,number))%!d!(A:Light Nav, bool) 1 == (L:local_sun_angle, number) 10 < && if{ (K:TOGGLE_NAV_LIGHTS) ! (>K:TOGGLE_NAV_LIGHTS) }(A:Light Nav, bool) 0 == (L:local_sun_angle, number) 10 > && if{ (K:TOGGLE_NAV_LIGHTS) ! (>K:TOGGLE_NAV_LIGHTS) }"Still digging further..."Jan"Procul Negotiis"

##### Share on other sites

Where is your gauge with invisible element placed? On the VC or on the 2D panel? Wasn't there a problem with "invisible" gauges on the VC reported lately?Arne Bartels

##### Share on other sites

Ok next try. I checked your code in an "invisble" part of a gauge on the 2D panel, and displaying the L: result in the same gauge in a element. I found some things. First the writing to a L: variable must be accompagnied with the unit (>L:anyname,number) not (>L:anyname). Then always a gap of at least one space after a '{' or before and after a '}' (never a space between 'els' and '{' or 'if' and '{', I made that mistake recently). And last, never a carriage return in a (...) statement, your (A:PLANELATITUDE, degrees)wasn't evaluated properly.Result: (P:ZULU TIME,hours) (A:PLANE LONGITUDE,degrees)15 / + (P:ZULU DAY OF YEAR,number) 3 - 365.25 / 2.0 pi * *sin 7.3 * (P:ZULU DAY OF YEAR,number) 80 - 365.25 / 4.0 pi ** sin -9.8 * + 60 / - (>L:local_sun_time,number)(P:ZULU DAY OF YEAR,number) 80 - 365.25 / 2.0 pi * * sin 23.5* (L:local_sun_time,number) 24.0 / 2.0 pi * * cos 90 (A:PLANE LATITUDE, degrees) abs - * (A:PLANE LATITUDE, degrees) 0> if{ - }els{ + } (>L:local_sun_angle,number)Arne Bartels

##### Share on other sites

Arne,Was this answer for frather Bill?I had no problems, functions perfect!Btw. have now a pretty stable fmc.Completed uneventfully EHAM-KLAX with SID, Transatl. Waypoints, STAR and Approach.With automatic speed- and altitude settings and light changes (sunangle!!)Now after take-off only LNAV and VNAV etc...Going to fly a Cessna.Jan"Procul Negotiis"

##### Share on other sites

Yes it was for Bill.Arne Bartels

##### Share on other sites

Yes, it appears to work perfectly. Thanks Arne and others involved in this. The only "problem" was that a direct copy and paste introduced the errors Arne described - those lacking but highly important spaces in the code.The following text element uses the now calculated sunangle and panel light switch to determine a bright or dark cockpit, and dims the radio accordingly:Anyone up for taking aircraft elevation, earths curvature, and aircraft HPB angle into account? Hehe, just kidding :DAgain, thanks a lot. I've been playing around with this without success from time to time. Finally!!! Yes! :)

##### Share on other sites

>Ok next try. I checked your code in an "invisble" part of a>gauge on the 2D panel, and displaying the L: result in the>same gauge in a element. >I found some things. >First the writing to a L: variable must be accompagnied with>the unit > (>L:anyname,number)> not> (>L:anyname).I have the 'gauge' installed to a 2d panel, in fact not 'invisible' at all, since I wanted to see the L: variable displayed while I worked.The function displays the L: variable regardeless of whether the 'units' is used in the formula or not. >Then always a gap of at least one space after a '{' or before>and after a '}' (never a space between 'els' and '{' or 'if'>and '{', I made that mistake recently). There is exactly ONE space between the { x } wherever used...>And last, never a carriage return in a (...) statement, your >(A:PLANE>LATITUDE, degrees)>wasn't evaluated properly.Even using "text mode", the forum software inserts carriage returns and wordwraps long lines. The formula in the actual .xml gauge has no carriage returns, but is one long, long line! :)I'm going to post a screen shot showing the results at present.BillAVSIM OmbudsmanFounder and Director,Creative Recycling of Aircraft Partshttp://mtco.com/~rsam/fartslogo.jpg

##### Share on other sites

In the screenshot that follows, the upper display contains the 'formula' a string display of the calculated L: variable and has the 'autoswitch' logic.The second display has only a string function to display the calculated L: variable.As you can plainly see, the calculated value is displayed on the top, but the lower has only ZEROS displayed, showing that the L: variable is truly empty! BillAVSIM OmbudsmanFounder and Director,Creative Recycling of Aircraft Partshttp://mtco.com/~rsam/fartslogo.jpghttp://forums.avsim.com/user_files/7170.jpghttp://forums.avsim.com/user_files/7171.jpg

##### Share on other sites

>Anyone up for taking aircraft elevation, earths curvature, and>aircraft HPB angle into account? Hehe, just kidding :D>"Fortunately" there is no need for this, in FS the world very flat, as you stated already. My formula is still not perfect, it has still errors up to +-3

##### Share on other sites

Hi, Fr. Bill.A couple of things may help. If you use NotePad, try to post a pic. with the code in NotePad, Wrap On, or maybe someone else can post the pic. with the proper syntax. I do not have time right now to try the code, but I will do it later, and post, if no one does it before.There is a XMLNotepad that may help, it's called "xpsetup.exe", about 300k, I can EMail it to you if you want, I got it from MS site? long ago. This helps with the Syntax Errors. If I copy the code directly from the AVSIM posts I get a lot of Errors. I hope it helps.You are right about the Sun position, overdone, I wish there was away to Hex edit the code and disable it. Thanks, to all you guys, for all the work you put into this sim. TV

## Create an account

Register a new account

• Tom Allensworth,
Founder of AVSIM Online

• ### Hot Spots

• Flight Simulation's Premier Resource!

AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!