Determine Your Region's Latitude
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-19-2009 22:36
I was doing some sun tracking for a project--a globe that shades itself to reflect what time of SL day it is--and ran into the question of what "latitude" I was at, or if the question made sense at all. So I wrote this little script to track the path of llGetSunDirection() and determine a normal to the plane of the path. That tells you the direction the "north pole" points, and the difference between the pole's direction and straight up (region's z-axis), I calculated latitude. This could be very useful for any scripts that want to determine the "time of day" or "season of the year" or what have you, though we might have to do some more investigation to see if the latter changes. The interesting thing is that the direction of the pole DOES seem to be consistent, and the latitude of the one region I've tested it in is about 54 degrees, plus or minus 2 degrees (North; the script will report South latitudes as negative). What I'm really interested in is whether latitude changes at all across the grid, so if you want to run this for an hour or two and post your results, we might all learn something! Here are some sample outputs: [2009/01/19 18:06] LatitudeTest: Latitude Avg: 54.964640 Latitude Std: 1.173124 <0.000099, 0.602614, 0.798033> <-0.001208, 0.601778, 0.798663> <-0.002556, 0.601009, 0.799238> <-0.003988, 0.600285, 0.799776> <-0.005492, 0.599617, 0.800269> <-0.006943, 0.599055, 0.800677> <-0.008396, 0.598573, 0.801024> <-0.009768, 0.598192, 0.801293> <-0.010978, 0.597918, 0.801482> <-0.012098, 0.597723, 0.801611> [2009/01/19 18:58] LatitudeTest: Latitude Avg: 53.805680 Latitude Std: 0.394022 <-0.012057, 0.597364, 0.801880> <-0.007713, 0.596007, 0.802943> <-0.002322, 0.593086, 0.805136> <0.002462, 0.589032, 0.808106> <0.005456, 0.585017, 0.811002> <0.006583, 0.582321, 0.812932> That's average, standard deviation, and the vectors are the last few pole directions noted by the script (remembers up to 10 of them) for sanity. Notice that there is no East-West (x) component to the pole direction. That's a relief! Anywhere, here is the code. As the sole content creator, I hereby give anyone permission to use it for any purpose whatsoever. Use it, copy it, change it, redistribute it, whatever. I take no liability for any damages that might occur due to its use (though I think you'd have to try pretty hard...). // MeasureLatitudeFromSunPath v1.0
float TIMER_PERIOD = 30.0;
float MIN_DIR_CHANGE = 0.2;
integer POLE_DIR_MEM_MAX_LEN = 10;
list sunDirMem = []; list poleDirMem = [];
float latitudeSum = 0.0; float latitudeSqSum = 0.0; integer nSamples = 0;
report() { if (nSamples <= 0) { llOwnerSay("Not enough samples. Please try again."); return; } float latitudeAvg = latitudeSum/nSamples; float latitudeVar = latitudeSqSum/nSamples-latitudeAvg*latitudeAvg; float latitudeStd; if (latitudeVar < 0.0) { latitudeStd = 0.0; } else { latitudeStd = llSqrt(latitudeVar); } llOwnerSay( "\nLatitude Avg: "+(string)latitudeAvg+ "\nLatitude Std: "+(string)latitudeStd+ "\n"+llDumpList2String(poleDirMem, "\n")); }
default { state_entry() { llSetTimerEvent(TIMER_PERIOD); } timer() { vector sunDir = llGetSunDirection(); integer nPrevSunDirs = llGetListLength(sunDirMem); if (nPrevSunDirs <= 0) { sunDirMem += [ sunDir ]; return; } vector sunDirM1 = llList2Vector(sunDirMem, -1); if (llAcos(sunDirM1*sunDir) < MIN_DIR_CHANGE) { return; } sunDirMem += [ sunDir ]; if (nPrevSunDirs < 2) { return; } else if (nPrevSunDirs >= 3) { sunDirMem = llList2List(sunDirMem, -3, -1); } vector sunDirM2 = llList2Vector(sunDirMem, -3); vector poleDir = -llVecNorm((sunDirM1-sunDirM2)%(sunDir-sunDirM1)); if (llGetListLength(poleDirMem) >= POLE_DIR_MEM_MAX_LEN) { poleDirMem = llList2List(poleDirMem, 1, -1); } poleDirMem += [ poleDir ]; float latitude = llAsin(poleDir.z)*RAD_TO_DEG; float latitudeSq = latitude*latitude; latitudeSum += latitude; latitudeSqSum += latitudeSq; ++nSamples; }
touch_start(integer nDetected) { key owner = llGetOwner(); integer i; for (i = 0; i < nDetected; ++i) { if (llDetectedKey(i) == owner) { report(); } } } }
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
01-20-2009 08:32
Wouldn't it be great if some day in the future someone discovered that SL was actually on the surface of a large sphere, and not flat?
_____________________
So many monkeys, so little Shakespeare.
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
01-20-2009 12:04
I didn't actually look at the code, but I took three readings. First reading at high altitude on the North continent, Heterocera, at global coordinates <258418, 262634, 3202> Latitude Avg: 45.837630 Latitude Std: 1.106542 <-0.020802, 0.695768, 0.717966> <-0.012553, 0.690799, 0.722937> <-0.006371, 0.684959, 0.728553> <-0.003027, 0.679725, 0.733461> <-0.002099, 0.676562, 0.736382> <-0.002101, 0.676352, 0.736575> <-0.001266, 0.679047, 0.734094> <0.001820, 0.683754, 0.729710> <0.007474, 0.689010, 0.724713> <0.014860, 0.693410, 0.720390> Second reading, directly beneath the first, at altitude 202 Latitude Avg: 45.842510 Latitude Std: 1.106828 <-0.022536, 0.696536, 0.717167> <-0.013939, 0.691828, 0.721928> <-0.007177, 0.685931, 0.727631> <-0.003323, 0.680357, 0.732874> <-0.002135, 0.676847, 0.736121> <-0.002111, 0.676144, 0.736766> <-0.001567, 0.678304, 0.734780> <0.000908, 0.682613, 0.730780> <0.006068, 0.687920, 0.725761> <0.013305, 0.692656, 0.721145> Third reading on the south continent, Jeogeot, at global coordinates <264013, 236645, 56> Latitude Avg: 45.843440 Latitude Std: 1.106919 <-0.015534, 0.692877, 0.720888> <-0.008338, 0.687158, 0.726460> <-0.003907, 0.681434, 0.731869> <-0.002255, 0.677437, 0.735578> <-0.002103, 0.676039, 0.736863> <-0.001840, 0.677527, 0.735496> <0.000077, 0.681438, 0.731876> <0.004661, 0.686712, 0.726915> <0.011631, 0.691755, 0.722038> <0.019454, 0.695260, 0.718495> So, that's about 26km separation in the Y dimension (small continents  ), with essentially difference in measured latitude. Was the earlier, 54 degree measurement taken on an island very, very far north? (I know altitude shouldn't make any difference to the geometry, and it didn't. It was just an easy datapoint to collect.)
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-20-2009 19:11
My original test was done on a private island near 220000, 260000 (the estate is closed to the public and not owned or managed by me, so I'd rather not give exact location). I'll have to test on other islands and parcels too, to give us better datapoints. Very strange. Is there a region/estate setting that might affect measured altitude? I hope they don't vary it with TIME. 
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-20-2009 20:22
I've just left probes in several regions, mostly sandboxes (many mainland, but at least one private island). Tried to get a decent spread across the grid. I modified the script to stop collecting data on rez, so that auto-return will place the object in my inventory and I can simply rez and click for a report. Each object description shows the region name and coordinates where they are collecting data.
So in a few hours (or maybe tomorrow) I'll have some more information to report. I'm also measuring again in the region where I first tested, to see if it has changed over time.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-20-2009 21:00
Well darn. The latitude of my original test location has changed over the last 24 hours. Here's some data from this evening.
[20:59] MeasureLatitudeFromSunPath whispers: Latitude Avg: 50.199520 Latitude Std: 0.358176 <0.004595, 0.633575, 0.773667> <0.010039, 0.635920, 0.771689> <0.013550, 0.636726, 0.770971> <0.013656, 0.636732, 0.770964> <0.010243, 0.637107, 0.770708> <0.004563, 0.638710, 0.769434> <-0.001408, 0.641594, 0.767043> <-0.005861, 0.644931, 0.764218> <-0.007972, 0.647394, 0.762114> <-0.008140, 0.647733, 0.761824>
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-20-2009 21:05
Explorers Rangeland 251904, 270848
[21:04] LatitudeMeasuringProbe whispers: Latitude Avg: 50.932070 Latitude Std: 0.598597 <-0.011627, 0.647661, 0.761840> <-0.017830, 0.639462, 0.768616> <-0.026427, 0.632192, 0.774361> <-0.035331, 0.627272, 0.777999> <-0.042072, 0.624993, 0.779496> <-0.044604, 0.624589, 0.779679> <-0.042216, 0.624566, 0.779830> <-0.035590, 0.623338, 0.781142> <-0.026669, 0.619870, 0.784251>
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-20-2009 21:09
Sandbox Cordova 255744, 255232
[21:09] LatitudeMeasuringProbe whispers: Latitude Avg: 50.035390 Latitude Std: 0.321405 <0.013970, 0.636741, 0.770951> <0.011314, 0.636926, 0.770842> <0.005920, 0.638227, 0.769826> <-0.000190, 0.640889, 0.767634> <-0.005052, 0.644214, 0.764829> <-0.007687, 0.646976, 0.762472> <-0.008216, 0.647892, 0.761688> <-0.007752, 0.646126, 0.763192>
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-20-2009 21:12
Sandbox Goguen 255488, 255232
[21:12] LatitudeMeasuringProbe whispers: Latitude Avg: 50.021490 Latitude Std: 0.314271 <0.013670, 0.636730, 0.770965> <0.010229, 0.637107, 0.770707> <0.004549, 0.638717, 0.769428> <-0.001404, 0.641593, 0.767044> <-0.005823, 0.644901, 0.764244> <-0.007959, 0.647377, 0.762128> <-0.008146, 0.647748, 0.761811> <-0.007669, 0.645331, 0.763864>
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-20-2009 21:14
Sandbox Island 254464, 255488
[21:14] LatitudeMeasuringProbe whispers: Latitude Avg: 49.964790 Latitude Std: 0.293657 <0.010595, 0.637037, 0.770761> <0.004903, 0.638574, 0.769545> <-0.001177, 0.641454, 0.767161> <-0.005694, 0.644783, 0.764345> <-0.007912, 0.647305, 0.762190> <-0.008166, 0.647793, 0.761772> <-0.007685, 0.645526, 0.763700>
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-20-2009 21:19
Sandbox France 152832, 237312
[21:19] LatitudeMeasuringProbe whispers: Latitude Avg: 49.804640 Latitude Std: 0.171151 <-0.005118, 0.644265, 0.764785> <-0.007714, 0.647014, 0.762439> <-0.008213, 0.647890, 0.761690> <-0.007750, 0.646088, 0.763223> <-0.007864, 0.641494, 0.767087>
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-20-2009 21:23
Hyboria 260352, 235520
[21:23] LatitudeMeasuringProbe whispers: Latitude Avg: 49.884380 Latitude Std: 0.242816 <-0.002861, 0.642539, 0.766247> <-0.006679, 0.645756, 0.763515> <-0.008167, 0.647738, 0.761820> <-0.008005, 0.647341, 0.762158> <-0.007638, 0.644103, 0.764900> <-0.008609, 0.638235, 0.769793>
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-20-2009 21:31
Pondex 227328, 294656
[21:31] LatitudeMeasuringProbe whispers: Latitude Avg: 50.013980 Latitude Std: 0.382617 <-0.008216, 0.647893, 0.761687> <-0.007751, 0.646114, 0.763202> <-0.007859, 0.641503, 0.767080> <-0.009976, 0.634610, 0.772768>
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-20-2009 22:40
From that data it appears that "latitude" doesn't change from place to place on the grid, but slowly changes over time. Like the whole SL grid slowly travels over the globe. LOL. Or it's just a very wacky path the sun takes, perhaps a path with slight random variation each cycle or each RL day. I guess the lesson is that accounting for latitude in sun tracking is going to have to either be very approximate, or take advantage of a script like this running pretty constantly in the background that can report the current direction of the pole. Craziness. EDIT: Oops. I guess I should look at the OFFICIAL wiki every once in a while. There's some info about sun direction there, though it is somewhat obtuse and doesn't include all the constants necessary to know what the heck it is doing: http://wiki.secondlife.com/wiki/LlGetSunDirection
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-21-2009 00:26
Hmm. And analyzing the logic on that page, it would seem the "latitude" would cycle every 44 RL hours, though between about 40 and 50 degrees rather than 45 and 55. The stupid local z shift in the center of the orbit would not make my calculation of the pole direction incorrect. There might be SOME merit to this script's logic after all. It just has to be understood that: 1.) The Grid wanders up and down in latitude over the course of a 44-hour "year". This is a very odd way of producing "seasons", and I'm really not sure what the heck LL was thinking there. 2.) The season is always a sort of Summer (and I say "sort of" because a REAL Summer would be produced by offsetting the Sun's "orbit" in the direction of the pole, not the local "up"  . This is all if the info on the referenced page is still correct. While it seems doubtful LL has touched that code in eons (without some kind of critical JIRA), the data we're coming up with doesn't QUITE match, nor does Zyzzy Zarf's "simplified" calculation using collected data produce QUITE the correct sun direction (though it is close). Zyzzy's theoretical calculation and the actual result of llGetSunDirection(): [0:23] SunDirTheoryTest whispers: Sun Direction: Thoeretical: <0.63533, -0.31343, 0.70578> Actual: <0.64252, -0.35577, 0.67867> [0:23] SunDirTheoryTest whispers: Sun Direction: Thoeretical: <0.63306, -0.31487, 0.70717> Actual: <0.64001, -0.35763, 0.68007> [0:23] SunDirTheoryTest whispers: Sun Direction: Thoeretical: <0.63078, -0.31631, 0.70856> Actual: <0.63748, -0.35948, 0.68146> Could the difference be floating point round-off errors, because SL only gives us 32-bit floats (and 6 digits of decimal precision in floating-point constants)? I don't know. Seems like a pretty big difference for just that explanation....
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-21-2009 00:31
It occurs to me that the same calculation probably exists in the viewer code, since you can set environmental settings to differ from the sim's. Maybe I'll peck around in the viewer source code to see if I can find it, though there's no guarantee they actually MATCHED the logic between the viewer and the server. LOL.
|
|
Claudius Sewell
Registered User
Join date: 8 Sep 2007
Posts: 8
|
02-02-2009 21:03
From: Hewee Zetkin though there's no guarantee they actually MATCHED the logic between the viewer and the server. LOL. Yes, LOL, It seems they are not matched since WindLight. Before WL I could look through my telescope at the sun thru llSunDirection() and actually see the sun in the visor. But with WL the sun is NOT at llSunDirection(). For example, it rises east and just climbs up for a while, and then decides to take some azimuth in account. Setting the east-angle in enviroment settings only rotates the orbit around the z-axis, so diminishing sun-rise azimuth also diminish sun-set azumuth. But I read somewhere that this will be fixed (someday)
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
02-03-2009 03:33
Right. After examining the viewer source, I've come to the conclusion that you can't set a virtual time of day from the viewer. You set the sun's position literally. So there's no equivalent client-side position calculation to verify against what the Lindens have said in the past about the server logic.
One interesting thing I learned from looking at the viewer code is that they do a very odd little tweak as the sun approaches noon. There is a comment that mentions good lighting for builders doing bump maps or some crazy thing like that, and they push the sun down (I think to the South) when it's close to noon. The closer to noon, they more they shove it (interpolate position) toward a fixed point. It definitely affects the light source direction. I'm not 100% about the drawn position of the sun texture, but I think that's changed too. Man, talk about a mess of ugly spaghetti code!
|