Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want it to be physically accurate, you actually need to consider two offsets: a vertical (depending on the current date) and a horizontal (depending on the current time).</p> <p>The horizontal offset X may be calculated by looking at the current time on some fixed geographic location on earth. The shadow offset will be 0 at midnight and will increase by 1/86400 for each seconds after midnight. So the formular is</p> <pre><code>offsetX = (curHour*3600 + curMinute*60 + curSeconds)/86400 </code></pre> <p>The vertical offset will change between the <a href="http://en.wikipedia.org/wiki/Solstice" rel="nofollow">Solstices</a> on June 21st and Dec 22nd (if it's not a leap year, where the Solstices are on June 20th and Dec 21st). The maximum angles are 23.44° in both directions. We have 90° per hemisphere and 365/2 = 182.5 days between the two solstices, and we are working with a mapping of a circular motion, so a sin()-function has to be used. The wavelength of a sinus wave is 2pi, so we need pi for half the vertical offset Y of one year.</p> <p>Please note, that I did not take leap seconds into account, so the calculation might be a bit off in the distant past/future.</p> <pre><code>// current time $curHour = date("H"); $curMin = date("i"); $curSec = date("s"); // resulting offset X $offsetX = ($curHour*3600 + $curMin*60 + $curSec)/86400; echo "======== OFFSET X ==========\n"; echo "curHour: $curHour\n"; echo "curMin: $curMin\n"; echo "curSec: $curSec\n"; echo "offsetX: $offsetX\n\n"; // spring equinox date as day of year $equinox = date("z", mktime(0, 0, 0, 3, 20)); // current day of year // first line is for testing purposes //$curDay = date("z", mktime(0, 0, 0, 6, 21)); $curDay = date("z"); // Day offset, mapped on the equinox offset $offsetSin = ((365.25 - $equinox + $curDay)%365.25)/365.25; // sinus wave offset $offsetSinFactor = sin($offsetSin * 2 * pi()); // map onto angle $offsetY = $offsetSinFactor * 23.44; // optional: Mercator projection $degreesPerRadian = 180.0 / pi(); $offsetYmercator = atan(sinh($offsetY)) * $degreesPerRadian; // missing: mapping onto canvas height (it's currently // mapped on $offsetY = 90 as the total height of the // canvas. echo "========= OFFSET Y =========\n"; echo "equinox day: $equinox\n"; echo "curDay: $curDay\n"; echo "offsetSin: $offsetSin\n"; echo "offsetSinFac: $offsetSinFactor\n"; echo "offsetY: $offsetY\n"; echo "offsetYmerc: $offsetYmercator\n"; </code></pre> <p>You should be able to port this calculation to any language you want.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COThank you so much, that is exactly what I was looking for! [I have implemented it here](http://dev.rngr.org/experiments/canvas/sine-wave-fill.php) with javascript but am having some issues with how to adjust the x-offset. Also, I used an amplitude of half the map height... it that correct? Any further assistance you could provide based on the code in that link would be greatly appreciated. Also, I assumed your math is built for a mercator projection, right?
      singulars
    2. COThe x-offset is on the width of the map and should be a factor between 0 and 1 to multiply with your map width: `$finalOffsetX = $offsetX * $mapWidth`. I assumed a map with equi-distant angle lines for the Y-Offset. If you want it to work with the mercator projection, you'll have to add another factor to map the non-equi-distant angle lines in the y-axis *and* need to dynamically stretch your shadow canvas to get the correct result, as the shadow will change according to the projection angle and y-Offset. Question is: how physically correct do you want it to be?
      singulars
    3. COGreat, I now understand and will implement the x-offset. I actually looked at my code again and I don't think I am using the y-offset correctly. Where in the sin formula do I plug that number in? See the edit of the initial question for my current code. I need this to be fairly accurate and yes, with the mercator projection (what google maps uses) the y angle line distances diminish towards the poles... any ideas as to how the formula could be changed to fit the projection?
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload