# How to draw a global day night curve

I see many applications which have world-clock map, and I would like to make my own to enhance some of my mobile apps. I wonder if anybody has any knowledge where to start, how to draw a curved shadow representing the dawn and the sunset on the globe. See the example:

I think that this curve goes up and down and creates an artic day/night etc Perhaps there is some acceptable approximation formula without a need to load data for each our and each global parallel and meridian...

• How accurate do you want it to be? I.e., do you want the dark to extend further into the Arctic during their winter? Or do you just want the basic "it's about like this" approximation? – Tim Holt Jun 19 '12 at 15:30
• Well that is a good question, I guess not many people use iPhone or Android on the Poles, however Norway is somewhere on the edge and they will mark the app down if it is too inaccurate... Nevertheless an approximation should do it. – Lumis Jun 19 '12 at 15:38
• The reason I asked is because if you don't care that much about the poles, you could just overlay a semi-transparent image of the light/dark over a world map. If the center of the night/day image is the middle of the daylight part, just offset the image from the prime meridian based on how far off it is from noon GMT. You could do that easily with JavaScript CSS and applying an offset in code. I'm betting some web-based solutions work that way (except not the one you linked to). – Tim Holt Jun 19 '12 at 21:39
• I can create a shadow image easily using canvas and fill-paths. I just need a data for a curve for at least each week. I doubt that one single image could work longer than a month or two, though for a little window like 200x300 pix I guess accuracy would not be too important. Thanks for the comments. – Lumis Jun 19 '12 at 21:50
• You can get a reasonable stab at the accuracy: your world map is 300 pixels and 24 hours wide; any error smaller than (24*60/300) minutes is less than one pixel => less than 5 minutes. – MSalters Jun 25 '12 at 12:56

You can calculate this using some basic trigonometry.

Here is a very nice and well documented explanation of how to calculate the length of day and the duration of twilight for any latitude and for any day of year.

You can also read this discussion on http://mathforum.org which mention an article in Ecological Modeling, volume 80 (1995) pp. 87-95, called "A Model Comparison for Daylength as a Function of Latitude and Day of the Year."

This article presented a model that apparently does a very good job of estimating the daylight - the error is less than one minute within 40 degrees of the equator, and less than seven minutes within 60 degrees and usually within two minutes for these latitudes.

I figured that if other people were having trouble finding this information, too, maybe it would be worth saving them some time by letting you know what I found. So, here's the model:

D = daylength

L = latitude

J = day of the year

P = asin(.39795*cos(.2163108 + 2*atan(.9671396*tan(.00860(J-186)))))

D = 24 - (24/pi)*acos( (sin(0.8333*pi/180) + sin(L*pi/180)*sin(P)) / (cos(L*pi/180)*cos(P)) )

Use a radian mode here, but latitude should be entered in degrees.

Note, that the day of year J probably does not start with the January 1st, but with the day of the winter solstice in the first year a four years cycle.

Using this, you should be able to generate the day/night curves you need so it almost matches the reality.

• Thank you, that is a big help! When I create a curve for a day in a year, I will just need to shift it left or right through the time-zones... – Lumis Jun 19 '12 at 21:32