Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Phases of the earth

Reply
Thread Tools

Phases of the earth

 
 
Ivo
Guest
Posts: n/a
 
      07-06-2006
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/javascrip...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/uncg.../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



 
Reply With Quote
 
 
 
 
Jeremy
Guest
Posts: n/a
 
      07-07-2006
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/javascrip...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/uncg.../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.background Position = 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
 
Reply With Quote
 
 
 
 
Ivo
Guest
Posts: n/a
 
      07-07-2006
"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/uncg.../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.background Position = 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


 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      07-07-2006
JRS: In article <44ad8b60$0$84011$(E-Mail Removed)>, dated Fri,
7 Jul 2006 00:14:51 remote, seen in news:comp.lang.javascript, Ivo
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Jeremy
Guest
Posts: n/a
 
      07-07-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Life Phases of a Ruby Method Dan Rathbun Ruby 1 09-06-2010 01:23 AM
What on earth is this? I didn't type those crypto commands!! Alec Waters Cisco 3 03-05-2009 01:48 AM
Three Phases To Email Sensitivity bs866806@163.com VHDL 0 01-08-2008 12:33 PM
MS Virtual Earth (the 3d image/mapping program equiv. to Google Earth). For Anyone Using. Robert11 Computer Support 1 11-16-2006 10:29 PM
who on earth is Yowdy Rates? tjones MCSE 9 11-08-2004 11:29 AM



Advertisments