# West with the Night, or East or North or South

May 12, 2010 4:00 PM Subscribe

Posting for brand-new user mdonnahoo, who will answer any queries in the thread: I am writing a program to determine how much time in a flight from Point X to Point Y occurs at night for pilot logging purposes. Is there an elegant way to calculate this?

Nighttime, in this context, is basically 1 hr after sunset to 1 hr before sunrise. So the givens are: date, time (in UTC), latitude and longitude and the time of sunset and sunrise at the point of departure and destination. It is assumed that the flight followed a great circle route and wasn't delayed, thus the speed is simply the distance traveled / time.

Because of the assumptions the accuracy need only be within a few minutes but generally speaking, the more accurate the better (it's already approximate enough as it is).

I found a list of equations that gets me close, but the best I can come up with based on these is to use a "brute force" method and calculate a destination point every few miles and check to see if it's nighttime yet at that location. I'm sure this method would work but it's slow and inelegant and it seems like there should be a relatively simple formula to determine where (or more specifically when) along the route nighttime occurred. Any help would be appreciated.

Nighttime, in this context, is basically 1 hr after sunset to 1 hr before sunrise. So the givens are: date, time (in UTC), latitude and longitude and the time of sunset and sunrise at the point of departure and destination. It is assumed that the flight followed a great circle route and wasn't delayed, thus the speed is simply the distance traveled / time.

Because of the assumptions the accuracy need only be within a few minutes but generally speaking, the more accurate the better (it's already approximate enough as it is).

I found a list of equations that gets me close, but the best I can come up with based on these is to use a "brute force" method and calculate a destination point every few miles and check to see if it's nighttime yet at that location. I'm sure this method would work but it's slow and inelegant and it seems like there should be a relatively simple formula to determine where (or more specifically when) along the route nighttime occurred. Any help would be appreciated.

Just off the top of my head, I would think you would have to:

D(day hours)=0

N(night hours)=0

Decide if departure was during the day or night. For departure during the day,

[here]

Calculate where on the earth the day/night boundary is, and treat it like it is another moving aircraft along the plane in question's great circle path, moving east to west. Then you would calculate where these two moving 'targets' would intersect

If they would not, then D is the total trip time. Otherwise

Take that position and calculate how long it would take your plane to get to that point from departure.

Add that time to D

Go back to [here], calculating for N (in case the flight was long enough to see morning again)

Since the path is a great circle at some inclination, and not a straight east-west path, the speed the day/night boundary moves along the plane's path will vary, so this is still a pretty difficult problem for my high school math. You'd have to parameterize the path's equation into a north-south and east-west component, which I don't know how to do.

Good challenge, though. I'm writing this down for when I'm bored at work next. (shh. Don't tell my boss.)

posted by ctmf at 4:56 PM on May 12, 2010

D(day hours)=0

N(night hours)=0

Decide if departure was during the day or night. For departure during the day,

[here]

Calculate where on the earth the day/night boundary is, and treat it like it is another moving aircraft along the plane in question's great circle path, moving east to west. Then you would calculate where these two moving 'targets' would intersect

If they would not, then D is the total trip time. Otherwise

Take that position and calculate how long it would take your plane to get to that point from departure.

Add that time to D

Go back to [here], calculating for N (in case the flight was long enough to see morning again)

Since the path is a great circle at some inclination, and not a straight east-west path, the speed the day/night boundary moves along the plane's path will vary, so this is still a pretty difficult problem for my high school math. You'd have to parameterize the path's equation into a north-south and east-west component, which I don't know how to do.

Good challenge, though. I'm writing this down for when I'm bored at work next. (shh. Don't tell my boss.)

posted by ctmf at 4:56 PM on May 12, 2010

You could make the greatly simplifying assumption that the day/night boundary moves at a constant rate along the path. That wouldn't seem to be too bad for common situations like a NY-LA flight, but you could come up with some possible paths for which that would be pretty inaccurate. For instance, how would an over-the pole flight calculation be affected? Ouch, you're hurting my mind already.

posted by ctmf at 5:01 PM on May 12, 2010

posted by ctmf at 5:01 PM on May 12, 2010

Thanks for the replies..

I have implemented a formula that calculates the sunrise / sunset time given a date and location so that's a good start.

My initial solution was very similar to what ctmf mentioned, knowing where and at what time you started and how many degrees of longitude the flight crossed you could calculate at what longitude nighttime would be and from there determine the time. Unfortunately that calculation assumed a straight course which falls apart if the flight is a great circle route such as NY to London. I thought I had hit pay dirt when I came across the calculations for determining great circle routes but other than going through the course a few minutes at a time checking for night, I'm not sure how to go about it.

posted by mdonnahoo at 6:39 PM on May 12, 2010

I have implemented a formula that calculates the sunrise / sunset time given a date and location so that's a good start.

My initial solution was very similar to what ctmf mentioned, knowing where and at what time you started and how many degrees of longitude the flight crossed you could calculate at what longitude nighttime would be and from there determine the time. Unfortunately that calculation assumed a straight course which falls apart if the flight is a great circle route such as NY to London. I thought I had hit pay dirt when I came across the calculations for determining great circle routes but other than going through the course a few minutes at a time checking for night, I'm not sure how to go about it.

posted by mdonnahoo at 6:39 PM on May 12, 2010

Hopefully clarifying things:

Per FAR 1.1 night means the time between the end of evening civil twilight and the beginning of morning civil twilight, as published in the American Air Almanac, converted to local time. The one hour rule is only for logging landings to carry passengers.

posted by allthegoodnamesweretaken at 6:45 PM on May 12, 2010

Per FAR 1.1 night means the time between the end of evening civil twilight and the beginning of morning civil twilight, as published in the American Air Almanac, converted to local time. The one hour rule is only for logging landings to carry passengers.

posted by allthegoodnamesweretaken at 6:45 PM on May 12, 2010

allthegoodnamesweretaken,

You are absolutely correct. I'll redo my sunrise / sunset calculations so it represents evening and morning civil twilight. Thanks for the reminder.

posted by mdonnahoo at 7:14 PM on May 12, 2010

You are absolutely correct. I'll redo my sunrise / sunset calculations so it represents evening and morning civil twilight. Thanks for the reminder.

posted by mdonnahoo at 7:14 PM on May 12, 2010

ack, the FAA regs were explained in mdonnahoo's original question but I edited them out for the sake of brevity. sorry.

posted by Quietgal at 7:14 PM on May 12, 2010

posted by Quietgal at 7:14 PM on May 12, 2010

Being that I'm a pilot, not a computer guy, maybe it'll help to use the Almanac to help. You know exactly when civil twilight starts and ends at that locations, so check to see if the takeoff is after and the landing is before the times listed. If the takeoff is at night and the landing is at night, probably the whole flight is at night. That could simplify the calculations.

posted by allthegoodnamesweretaken at 12:08 AM on May 13, 2010

posted by allthegoodnamesweretaken at 12:08 AM on May 13, 2010

Sometimes brute force is good. It took me a long time as a programmer to accept that.

The more I thought about this problem the less I thought a "clever" solution was going to work well. I kept coming up with tricky cases like long west to east flights, or trans-polar flights, or north / south flights during the Winter.

How about just testing along the flight path, to some reasonable resolution; then if you get any day / night switches doing a binary search in that region to find the exact point of the switch. If that turns out to be slow you can try to improve your implementation of the basic formulas.

posted by ecurtz at 6:45 AM on May 13, 2010

The more I thought about this problem the less I thought a "clever" solution was going to work well. I kept coming up with tricky cases like long west to east flights, or trans-polar flights, or north / south flights during the Winter.

How about just testing along the flight path, to some reasonable resolution; then if you get any day / night switches doing a binary search in that region to find the exact point of the switch. If that turns out to be slow you can try to improve your implementation of the basic formulas.

posted by ecurtz at 6:45 AM on May 13, 2010

Or a binary search from the get-go. The first iteration should tell you whether you even need to go any further.

posted by TruncatedTiller at 8:33 AM on May 13, 2010

posted by TruncatedTiller at 8:33 AM on May 13, 2010

This thread is closed to new comments.

My impulse is that you can get a formula for the sunrise based on longitude and latitude and plug that into your position formula, but I won't attempt it myself.

posted by ecurtz at 4:20 PM on May 12, 2010