How to calculate the amount of night time during a flight? I have been asked to find a way to calculate the amount of time that a flight takes during night time.
So far, I have the departure latitude and longitude and the time of takeoff, the arrival latitude and longitude and the time of landing. I can easily calculate the sunset and sunrise time at the departure location, and at the arrival location. But I don't know how to proceed in order to find at which moment of the flight the sunrise and sunset will happen at the location where the aircraft is at that precise moment.
I'm just asking for some guidance on how to resolve this problem.
PS: The calculation does not have to be very precise, and estimation is more than enough. We are just looking for the simplest solution to obtain an acceptable result.
 A: The answer to this question involves quite a bit of spherical trigonometry. Call $(\lambda_1,\varphi_1)$ the longitude and latitude of the place of departure, and $(\lambda_2,\varphi_2)$ the coordinates of the destination. Let's assume that the plane travels along a great circle. Then it will travel a total angle $\theta$, given by
$$
\cos\theta = \sin\varphi_1\sin\varphi_2 + \cos\varphi_1\cos\varphi_2\cos(\lambda_2-\lambda_1).
$$
If $\theta$ is expressed it radians, then the corresponding distance is $D=\theta R_\oplus$, with $R_\oplus$ the radius of the Earth. Suppose that the total flight time is $T$, and that the plane flies at a constant speed. If $t$ is the time since take-off, then
$$
\begin{align}
\theta_1 &= \theta t/T,\\
\theta_2 &= \theta -\theta_1,
\end{align}
$$
where $\theta_1$ is the angle traveled by the plane at time $t$, while $\theta_2$ is the angle that the plane still has to travel. At time $t$, the plane will then be above the location $(\lambda,\varphi)$, given by
$$
\begin{align}
\cos\theta_1 &= \sin\varphi_1\sin\varphi + \cos\varphi_1\cos\varphi\cos(\lambda-\lambda_1),\\
\cos\theta_2 &= \sin\varphi_2\sin\varphi + \cos\varphi_2\cos\varphi\cos(\lambda-\lambda_2),
\end{align}
$$
from which $(\lambda(t),\varphi(t))$ can be derived (after some tedius calculations). 
If we know the Greenwhich Mean Solar Time $t_0$ at the moment of departure, then we can obtain the hour angle $H_\odot(t)$ of the Sun at $(\lambda(t),\varphi(t))$:
$$
H_\odot(t) + 12^\text{h}=t_0 +t + \lambda(t)\qquad\text{(modulo $24^\text{h}$)},
$$
where all variables are expressed in hours, minutes, and seconds (and $360^\circ$ corresponds with $24^\text{h}$). We also need to know the declination of the Sun $\delta_\odot$ during the flight (so we need to know the date). 
The altitude of the Sun $a_\odot(t)$ above the local horizon is then
$$
\sin a_\odot(t) = \sin\varphi(t)\sin\delta_\odot + \cos\varphi(t)\cos\delta_\odot \cos H_\odot(t)
$$
(see the wiki page on celestial coordinates). Sunset and sunrise correspond with $a_\odot=0^\circ$ on the ground (ignoring atmospheric refraction). Using simple trigonometry, it is easy to show that from the plane's perspective, at a height $h$, sunset and sunrise will occur when 
$$a_\odot= -\cos^{-1}(R_\oplus/(R_\oplus+h)).$$
A: One option would be to plot the course of the flight as a set of discrete points and check if it's day or night at each point along the way to determine when the flight enters/exits the Earths shadow.  Precision will be limited to the size of your time increment, but doing a once/minute check on a computer shouldn't be a problem. 
For a high precision result you'd need to program in actual flight corridors; but for a rough estimate assuming the shortest direct route will probably be good enough in most cases.
