These forums are CLOSED. Please visit the new forums HERE
Sun Tracking |
|
|
Grazel Cosmo
Registered User
Join date: 12 Mar 2005
Posts: 28
|
07-30-2006 17:06
I know how to do a quick check to see if its daytime or nighttime but was wondering if anyone knew the best way to detect the sun's position within day or night. Basically just need to know how far up in the sky the sun is or the moon should it be night. I know they're opposite so can easily track the sun and use the positve/negative Z to figure that out. I'm looking for a way to translate the sun's position vector into a way to rotate a dial so that midday has the sun pointing up on the prim, sunrise/sunset would have it on the sides, and midnight would have it at the bottom. I've noticed that the X,Y, and Z positions all change when the sun is updated and not sure which way is best to track the sun's angle above the horizion.
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
07-30-2006 19:16
I've noticed that the X,Y, and Z positions all change when the sun is updated and not sure which way is best to track the sun's angle above the horizion. If it's the angle you're interested in, then probably it's most convenient to check dot product of sun direction vector, and the same vector projected on flat plane. Something like: vector sun = llGetSunDirection(); float angle = llAcos( sun * llVecNorm( <sun.x, sun.y, 0.0> ) ); // angle in radians (this is completely untested and am dead tired so if it turns out wrong, sorry) You can determine high point from here by testing when the angle starts decreasing... no idea if this will be constant value or even the same in different sims, for that matter. They may be running some sort of simulation that takes into account geographical position of the sim, just to be cute. o.O; |
|
Bitzer Balderdash
Dazed and Confused
Join date: 21 Dec 2005
Posts: 246
|
07-31-2006 01:09
If it just day/night that you want to know, then simply check if the z component of the direction vector is positive or negative.
+ve is daytime -ve is night 0 is on the horizon. |
|
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
|
07-31-2006 05:03
I'd recommend you read through this post: /54/e7/107757/1.html
The reason that the x, y and z values change with each update is that the vector is normalised, which keeps the vectors length equal to 1 (from pythagoras x^2 + y^2 + z^2 = 1). As for the angle, Joannah's solution looks about right, though I can't test it just now myself. I have been gathering data of the suns movement and will post my results when I have something useful. At the moment it's looking like the sun follows the surface of an ellipsoid which has a centre offset from the orgin. _____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum |
|
Si Neumann
Registered User
Join date: 26 Apr 2006
Posts: 12
|
Eureka!?
08-02-2006 13:22
vector sun = llGetSunDirection(); float angle = llAcos( sun * llVecNorm( <sun.x, sun.y, 0.0> ) ); // angle in radians Let me get this right - does this give you the angle of the sun's height above ground level (in radians)? I'm not bothered about x or y. If SO, then multipying by 57.2957795 (i.e. the no. of degrees in a radian) will give the angle in degrees ... which ... is EXACTLY what i (and i'm sure many others) have been looking for all over this forum. ??? |
|
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
|
08-02-2006 13:42
... multipying by 57.2957795 (i.e. the no. of degrees in a radian) will give the angle in degrees ... or multiplying by RAD_TO_DEG an lsl global constant (with DEG_TO_RAD being it's counter-value). _____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum |
|
Si Neumann
Registered User
Join date: 26 Apr 2006
Posts: 12
|
Deg_to_rad
08-02-2006 14:15
Ha! Thanks Nand - i just spent an hour googling my mathes to work out that 57.2957795 value too!
I'm testing your script. At midday (SL 14:00 ish) just gone, your script said the sun was about 61 degrees (note not 90). This could be correct, i just thought it looked a little higher. I need a protractor! Are you pretty sure of the maths as this is great if it works. I've seen a few other solutions in other threads but they're giving very strange values. |
|
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
|
08-02-2006 14:32
Si, actually its Joannah Cramer's code and I haven't tested it.
The only code I've used with relation to the sun is a sundial. After a lot of head-scratching and scribbles on paper I came up with this (put it in a cylinder cut in half using sphere dimple end 0.5 and link it to a root prim (the standing part of the sundial perhaps)). CODE
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum |
|
Si Neumann
Registered User
Join date: 26 Apr 2006
Posts: 12
|
08-02-2006 14:42
Woops! Sorry Nand hope i didn't embarass you with the mis-credit!
Joannah - apologies! Have you tested this script? Does 61 degrees sound correct to you? Sundial looks interesting Nand - great idea! |
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
08-02-2006 16:01
Joannah - apologies! Have you tested this script? Does 61 degrees sound correct to you? Sundial looks interesting Nand - great idea! From memory 60 degree sounds quite accurate... i've been toying with sun-related scripts for a while, that included 'sunflower' kinds of scripts which aim prim constantly towards the sun... and while the angle can get pretty step by noon, i'd say it was never beyond some mid-point between 45 and 90 degrees. So yeah, ~60 degrees. you can test it yourself: CODE
drop it in a prim, wait for noon and see what angle (on local X axis) it's at -.o |
|
Spuds Milk
Registered User
Join date: 28 Sep 2004
Posts: 94
|
08-02-2006 18:16
as an excersize for the student, based on how off of straight up it is, you can figure out the latitute and longitude of the sim/SL
![]() |
|
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
|
08-03-2006 05:18
Woops! Sorry Nand hope i didn't embarass you with the mis-credit! ... Sundial looks interesting Nand - great idea! Not at all Si, credit where due. And thanks for the complement. drop it in a prim, wait for noon and see what angle (on local X axis) it's at -.o Alternatively, we could model the sun movement using recorded data (which I'll attempt when I get the chance). as an excersize for the student, based on how off of straight up it is, you can figure out the latitute and longitude of the sim/SL And then to top that, locate the prime meridian and the equator of SL. _____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum |
|
Binary Hextall
Registered User
Join date: 13 Jul 2006
Posts: 1
|
Thanks!
08-04-2006 03:39
Just what I was looking for. This is a big help for my solar station. I admit I created a monster if statment that looked at the time and decided if it fell within on of the six periods of daylight.
Also trying to get the sundirection ad telling the prim to look at it produced some interesting results, but not what I was looking for. |
|
Si Neumann
Registered User
Join date: 26 Apr 2006
Posts: 12
|
Confused
08-11-2006 16:40
drop it in a prim, wait for noon and see what angle (on local X axis) it's at -.o Tried this Joannah and it seems to work a treat. Have only had chance to test at night but when I enter edit mode the red X axis marker points straight through the centre of the moon! When i look at the angle of rotation though and compare it to the sun angle obtained from: vSunPos = llGetSunDirection(); float fSunAngle = llAcos( vSunPos * llVecNorm( <vSunPos.x, vSunPos.y, 0.0> ) ); fSunAngle *= RAD_TO_DEG; The value is always slightly different? Are these equivalent? How would I go about obtaining the Angle (in degrees) from your rotating prim method which seems to work perfectly? |
|
Si Neumann
Registered User
Join date: 26 Apr 2006
Posts: 12
|
Hmm
08-11-2006 17:12
No, on further looking they're both consistent with each other.
If I add the Y-Axis angle of rotation from the rotating prim to the angle obtained from the horrible llAcos() formula I always get exactly 360 degrees, so there is a 1 to 1 relationship there which I think proves the 2 formulae are working in the same way - just that the origins and direction of the arcs are different! If you know what i mean!!! Anyway, the upshot IS that I totally trust this formula now. THANKS to everyone that conributed to this thread!!! |
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
08-11-2006 17:13
The value is always slightly different? I'd guess the difference comes from SL using conversion from rotation to Euler angles in order to show values in the build window, plus they're being rounded up to two decimal points on top of it. For example, i tried it right now and the build window reports angle of ~7 degree on Y axis, *but* ~337 degree on X axis ... while the box is actually aiming ~23 degree below horizon at sun buried there. Which in weird way does match because (360 - 23 = 337) This is the very reason why Euler conversion isn't reliable -- there's often more than one way to represent rotation with Euler angles, and no real way to 'enforce' results of conversion which would be 'logical' to viewer in world or even consistant on frame-per-frame basis. For the little it's worth the angle calculation and prim rotation i posted use the same bag of tricks, so i'd say the value you get with that angle calculation is quite reliable ^^;;; |
|
Nyoko Salome
kittytailmeowmeow
Join date: 18 Jul 2005
Posts: 1,378
|
08-11-2006 18:45
hey there!
i'm just making myself a 'weather gauge' tonight... and just for sake of cross-reference, i thought i'd post my lil' one-in-all script (it's a royal bee-otch searching the forums, y'know - maybe that's one reason to close 'em, but at the same time, that's losing a valuable resource:\i'm not sure i got the final advice for sun-tracking straight... please advise, if i'm off on my copy/paste. btw, this has some extras to it - usually this is my 'starting point' script for most stuff, so use away![]() CODE integer BLNtesting = TRUE; _____________________
![]() Nyoko's Bodyoils @ Nyoko's Wears http://slurl.com/secondlife/Centaur/126/251/734/ http://home.comcast.net/~nyoko.salome2/nyokosWears/index.html "i don't spend nearly enough time on the holodeck. i should go there more often and relax." - deanna troi |
|
Si Neumann
Registered User
Join date: 26 Apr 2006
Posts: 12
|
The SunAngle() function
08-12-2006 03:47
I've distilled everything learnt here into a simple function for anyone to cut 'n paste.
I've tested this thoroughly and its solid. CODE // Return the sun angle above the horizon in degrees. |
|
Armandi Goodliffe
Fantasy Mechanic
Join date: 2 Jan 2006
Posts: 144
|
08-12-2006 22:33
Ok. . I'm not understanding the whole maxing out at 60 degress for noon
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-12-2006 23:21
Ok. . I'm not understanding the whole maxing out at 60 degress for noon Well, here's an idea. That would happen in the real world on the equinoxes at 30 degrees North and South latitude.... (Well, approximately. The Earth isn't a perfect sphere.) |
|
Nyoko Salome
kittytailmeowmeow
Join date: 18 Jul 2005
Posts: 1,378
|
08-13-2006 08:09
hehe heck, midnight only went -19 or so, i noticed... and min/max may vary widely; hadn't watched the pattern long enough yet... well i'm planning next to put in prevPosition tracking to figure out whether the sun is 'waxing or waning' to do basic feedback like 'morning', 'afternoon' and such, until a better calculation for such is available.
terrific work, si!! it does the job very well!_____________________
![]() Nyoko's Bodyoils @ Nyoko's Wears http://slurl.com/secondlife/Centaur/126/251/734/ http://home.comcast.net/~nyoko.salome2/nyokosWears/index.html "i don't spend nearly enough time on the holodeck. i should go there more often and relax." - deanna troi |
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
08-13-2006 11:09
Ok. . I'm not understanding the whole maxing out at 60 degress for noon Speaking from way north of the tropic of cancer we never get the sun straight overhead. In midwinter it often fails to even clear the buildings it stays so low. In midsummer it only just sets, but the sky stays quite light. A bit further north from here you get continuous night in winter and continuous light in summer. The sun straight overhead thing is only if the sun is overhead... on the equator on an equinox say. _____________________
|
|
Nyoko Salome
kittytailmeowmeow
Join date: 18 Jul 2005
Posts: 1,378
|
hummmm...:\
08-13-2006 14:58
wow... bug in the sim??:\ or in the calculation?
sun position3: -0.17 (si's calculation) 'night' (0.905|0.425|-0.00) - direct feedback of llSunDirection()/whatchamacallit ... but it's mid-afternoon. i set the sun to midnight, then back to region default... and still get this calculation. something buggy in the Acos, or the multpication within the parenthesis??:\ p.s. well, shoot - if the llSunDirection is reading back negative, what is there to do?? that's a simbug. checking up on it... let you know if i have something to feed back... _____________________
![]() Nyoko's Bodyoils @ Nyoko's Wears http://slurl.com/secondlife/Centaur/126/251/734/ http://home.comcast.net/~nyoko.salome2/nyokosWears/index.html "i don't spend nearly enough time on the holodeck. i should go there more often and relax." - deanna troi |
|
Nyoko Salome
kittytailmeowmeow
Join date: 18 Jul 2005
Posts: 1,378
|
08-13-2006 15:01
wow, okay... just even returning to sl from the background, raw z is reading right now!! :| wondering if it varies now if sun is force-set to other times?? testing 'midnight' now... will tp out and back to see if the reading is different...
p.s. hmmm, well, the reading does now appear correct to region default. i dunno why i was getting that errant reading before... i'd cleared cache semi-recently; dunno if that had anything to do with it...:\ _____________________
![]() Nyoko's Bodyoils @ Nyoko's Wears http://slurl.com/secondlife/Centaur/126/251/734/ http://home.comcast.net/~nyoko.salome2/nyokosWears/index.html "i don't spend nearly enough time on the holodeck. i should go there more often and relax." - deanna troi |
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
08-13-2006 15:05
wow... bug in the sim??:\ or in the calculation? sun position3: -0.17 (si's calculation) 'night' (0.905|0.425|-0.00) - direct feedback of llSunDirection()/whatchamacallit ... but it's mid-afternoon. i set the sun to midnight, then back to region default... and still get this calculation. something buggy in the Acos, or the multpication within the parenthesis??:\ -0.17 degrees is nearly zero which matches quite well the -0.00(whatever) on Z axis llSunDirection is reporting. the mi-afternoon, did you set it with the 'set time of day' menu command? Because llSunDirection ignores anything you may have set client side, and only pays attention to actual state of the sim (i.e. what you get when you revert to region default) ... which is also why you were getting the same result no matter what time of day you set in your client. |