Phases of the earth

Discussion in 'Javascript' started by Ivo, Jul 6, 2006.

  1. Ivo

    Ivo Guest

    Hello all, while I am no astronomer or mathematician, I was wondering if
    anyone could shed some light on the following question.
    The phases of the moon have intrigued mankind since the dawn of time.
    Astronomers have spent the ages developing magical, eh, mathematical
    algorithms to predict (and postdict) the waning and waxing years and
    millenia ahead.
    Now plotting the current shape of the crescent in JavaScript, based on the
    internal clock, takes about twenty lines. See:
    <URL: http://www.eskimo.com/~jet/javascript/moonphase/moonphase.html >

    But there is another repetitive shadow, that we are increasingly seeing on
    computer generated world maps: that of the night. It 's the same kind of
    shadow, but cycling in just 24 hours, and projected on a flattened surface.
    So the question, does anyone know of a script that plots the current area's
    of dusk, night and dawn on a worldmap? Many servserside language seem
    capable of it, so it shouldn't be too difficult to implement in JavaScript
    with a given jpg or gif where the equator, dateline and Greenwich pixel
    positions are known.
    To get the idea, see the shaded sinus at for example these sites:
    <URL: http://www.fourmilab.ch/cgi-bin/uncgi/Earth/action?opt=-p >
    <URL: http://www.die.net/earth/ >

    Reinventing the wheel is silly, so translating an existing program to
    Javascript seems the most sensible approach, but I haven't been able to find
    the code for one just yet.
    Many thanks,
    ivo
    http://4umi.com/image/wallpaper/worldmap.jpg
     
    Ivo, Jul 6, 2006
    #1
    1. Advertising

  2. Ivo

    Jeremy Guest

    Ivo wrote:
    > Hello all, while I am no astronomer or mathematician, I was wondering if
    > anyone could shed some light on the following question.
    > The phases of the moon have intrigued mankind since the dawn of time.
    > Astronomers have spent the ages developing magical, eh, mathematical
    > algorithms to predict (and postdict) the waning and waxing years and
    > millenia ahead.
    > Now plotting the current shape of the crescent in JavaScript, based on the
    > internal clock, takes about twenty lines. See:
    > <URL: http://www.eskimo.com/~jet/javascript/moonphase/moonphase.html >
    >
    > But there is another repetitive shadow, that we are increasingly seeing on
    > computer generated world maps: that of the night. It 's the same kind of
    > shadow, but cycling in just 24 hours, and projected on a flattened surface.
    > So the question, does anyone know of a script that plots the current area's
    > of dusk, night and dawn on a worldmap? Many servserside language seem
    > capable of it, so it shouldn't be too difficult to implement in JavaScript
    > with a given jpg or gif where the equator, dateline and Greenwich pixel
    > positions are known.
    > To get the idea, see the shaded sinus at for example these sites:
    > <URL: http://www.fourmilab.ch/cgi-bin/uncgi/Earth/action?opt=-p >
    > <URL: http://www.die.net/earth/ >
    >
    > Reinventing the wheel is silly, so translating an existing program to
    > Javascript seems the most sensible approach, but I haven't been able to find
    > the code for one just yet.
    > Many thanks,
    > ivo
    > http://4umi.com/image/wallpaper/worldmap.jpg
    >
    >
    >


    To do that sinus thing, I would probably just overlay a PNG with a
    semi-transparent black sinusoid onto the world map and position it
    correctly. It would take some ugly tricks to make the PNG work in IE
    but I think it would be the simplest way.

    Disregarding IE (which I know you probably can't do, but this might give
    you an idea):

    HTML:
    <div id="worldMap">
    <div id="shadow"></div>
    </div>

    CSS:
    #worldMap
    {
    width: (width of worldmap image)px;
    height: (height of worldmap image)px;
    background-image: url((path to worldmap image));
    }

    #worldMap #shadow
    {
    width: 100%;
    height: 100%;
    background-image: url((path to shadow image));
    }

    JavaScript:
    function setMapTime(time)
    {
    /*...
    do some stuff to figure out horizontal
    position of maximum
    */

    document.getElementById("shadow").style.backgroundPosition = hPos + "px
    0px";
    //where hPos is the horizontal maximum's position in px
    }

    All you would really have to do is change the background-position of the
    shadow (assuming that image is tileable, which it should be). Of
    course, that won't work in IE since it won't support repeating PNG
    backgrounds until version 7 comes out. You could approximate the same
    thing using a GIF, but you wouldn't get the semi-transparency effect.

    Jeremy
     
    Jeremy, Jul 7, 2006
    #2
    1. Advertising

  3. Ivo

    Ivo Guest

    "Jeremy" schreef
    > Ivo wrote:
    >> So the question, does anyone know of a script that plots the current
    >> area's of dusk, night and dawn on a worldmap? Many servserside language
    >> seem capable of it, so it shouldn't be too difficult to implement in
    >> JavaScript with a given jpg or gif where the equator, dateline and
    >> Greenwich pixel positions are known.
    >> To get the idea, see the shaded sinus at for example these sites:
    >> <URL: http://www.fourmilab.ch/cgi-bin/uncgi/Earth/action?opt=-p >
    >> <URL: http://www.die.net/earth/ >

    >
    > To do that sinus thing, I would probably just overlay a PNG with a
    > semi-transparent black sinusoid onto the world map and position it
    > correctly. It would take some ugly tricks to make the PNG work in IE but
    > I think it would be the simplest way.
    >

    <snip>
    > JavaScript:
    > function setMapTime(time)
    > {
    > /*...
    > do some stuff to figure out horizontal
    > position of maximum
    > */
    >
    > document.getElementById("shadow").style.backgroundPosition = hPos + "px
    > 0px";
    > //where hPos is the horizontal maximum's position in px
    > }

    <snip>
    > You could approximate the same thing using a GIF, but you wouldn't get
    > the semi-transparency effect.
    >

    Thanks Jeremy, these techniques certainly come into play, but I think at the
    moment these are details compared to the bit in your comment block. What is
    the arithmetic? The sinus moves horizontally around the map every 24 hours,
    but it moves vertically every 365 days, changing shape all the time. Do we
    need that many images? I hadn't really thought about the transparancy
    problem, a plain dark area would be good enough for me, as long as every two
    or three pixels (hunderds of miles on the map) is accounted for. You can
    fake transparancy and oval shapes by plotting pixels, but there must a
    formula.
    Regards,
    Ivo
     
    Ivo, Jul 7, 2006
    #3
  4. JRS: In article <44ad8b60$0$84011$>, dated Fri,
    7 Jul 2006 00:14:51 remote, seen in news:comp.lang.javascript, Ivo
    <> posted :

    >The phases of the moon have intrigued mankind since the dawn of time.


    >But there is another repetitive shadow, that we are increasingly seeing on
    >computer generated world maps: that of the night. It 's the same kind of
    >shadow, but cycling in just 24 hours, and projected on a flattened surface.


    Not entirely. The Moon has no atmosphere, so it should be sufficient to
    indicate where the centre of the Sun (or its upper edge) is above the
    horizon.

    For the Earth, however, there are at least four boundaries to indicate;
    when the Sun's centre or top is on the horizon, and when the Sun's
    centre is 6 / 12 / 18 degrees below the horizon - Civil / Nautical /
    Astronomical Twilight boundaries. In each case one should allow for
    atmospheric refraction.

    <URL:http://www.merlyn.demon.co.uk/misctime.htm> and references,
    including Whitaker's Almanac.

    Since at least 99% of the Dutch seem to speak perfect English, Whitaker
    may well be available in the Netherlands; and, remembering Dutch
    maritime history, there should be a Dutch equivalent too!

    Or, no doubt, a Nautical Almanac, etc.

    In such a map, it would be interesting also to show the sub-solar point;
    and, by stepping in 24-h intervals, one can see the analemma.

    I have no code; try Googling "Paul Schlyter", which may help.
    Indeed, read the sci.astro FAQ, section C.03, via?
    <URL:http://sciastro.astronomy.net/>.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
    Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
    PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
    Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
     
    Dr John Stockton, Jul 7, 2006
    #4
  5. Ivo

    Jeremy Guest

    Ivo wrote:
    > Thanks Jeremy, these techniques certainly come into play, but I think at the
    > moment these are details compared to the bit in your comment block. What is
    > the arithmetic? The sinus moves horizontally around the map every 24 hours,
    > but it moves vertically every 365 days, changing shape all the time. Do we
    > need that many images? I hadn't really thought about the transparancy
    > problem, a plain dark area would be good enough for me, as long as every two
    > or three pixels (hunderds of miles on the map) is accounted for. You can
    > fake transparancy and oval shapes by plotting pixels, but there must a
    > formula.
    > Regards,
    > Ivo
    >
    >


    It changes shape? It moves vertically?

    I was looking at this site
    http://www.time.gov/timezone.cgi?Pacific/d/-8/java - which seems to do
    what you're trying to do, only in the form of a Java applet. The image
    they use seems pretty static to me, but maybe I'm wrong. Or, maybe you
    need a more precise graph.

    In any case, if it's just the math you're after, you might want to
    additionally ask in a math or physics group.

    The math you need actually depends on what method was used to project
    your world map. You'll need to come up with a function that maps the
    time of day to a three dimensional unit vector that points from the
    center of the earth to the sun. Then you'll need to use the same
    projection function as your world map (it's probably either a
    cylindrical projection or a spherical projection) to project the
    intersection of the plane defined by that vector with the orb of the
    earth into a curve. That is, if you want to be really precise about it.

    See, if you're not taking seasons into account, you can come up with a
    good approximation using a static projection that moves horizontally.
    Just use a world map that's projected onto the sun's viewing plane,
    rather than a polar axis-aligned viewing plane. I think this is what
    time.gov does, only they chop off equal amounts from the bottom and top
    so that you don't notice that the north pole is larger than the south
    pole in their projection (because you can see neither of them). Your
    map may look a little "askew", but will not be any less of an accurate
    representation.

    Jeremy
     
    Jeremy, Jul 7, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kackson
    Replies:
    4
    Views:
    2,915
    Eliyahu Goldin
    Nov 30, 2004
  2. Vijay
    Replies:
    11
    Views:
    4,429
    shashiki
    Jul 19, 2006
  3. Replies:
    5
    Views:
    7,722
  4. Replies:
    0
    Views:
    529
  5. Dan Rathbun

    Life Phases of a Ruby Method

    Dan Rathbun, Sep 5, 2010, in forum: Ruby
    Replies:
    1
    Views:
    182
    Ryan Davis
    Sep 6, 2010
Loading...

Share This Page