This note is supplementary to a previous one entitled "Sunrise Direction". The same model of Earth with respect to the Sun is used to predict the length of day, on any given day in the year, and anywhere on Earth.
We have three coordinate reference frames to relate, the first one (Frame 1) is the reference frame that has its center at the center of Earth, with the z-axis set perpendicular to the orbital plane (the plane in which the Earth orbits the Sun). Also, the x-axis is selected to point towards the center of the Sun.
The second reference frame (Frame 2) is attached to Earth, centered at the Earth center, with its z-axis along the axis of Earth rotation. The x-axis orientation, results naturally when we look at this frame as being the result of two consecutive geometric rotations, the first is about the z-axis (of the orbital plane). And the second is about the y-axis of the frame resulting from the first rotation.
Finally, the third frame (Frame 3), is the frame attached to a moving point on the surface of Earth, with its three axes pointing towards the standard directions of local East, local North, and local Vertical. Thus, let be the coordinate vector in the orbital plane, and be the corresponding coordinate vector in the frame resulting from the first rotation, and let be the corresponding coordinate vector in Frame 2. We can relate these three vectors as follows
where is the rotation matrix about the z-axis by an angle , and is given by
where is the rotation matrix about the y-axis by an angle , and is given by
Next, we consider Frame 3. We note that the unit vectors pointing East and North and Vertically Up, at a given point that has a latitude of is given by
Where is the rotation angle counterclockwise from the x-axis of the Earth reference frame.
Together, these three vectors form an orthornormal basis for the reference frame we name Frame 3, and can written with respect to frame 2 as
Now, in the orbital reference frame (Frame 1), the direction to the Sun is pointing in the positive x-direction,
It follows that the direction of the sun , when expressed with respect to Frame 3, is related to , by
Being a rotation matrix, the inverse of is its transpose. Performing the indicated multiplication, results in
Now, at sunrise , the z-component of this vector is zero, because the Sun will be coming from the horizon. So we need to solve for that will result in zero z-component of . To that end, let
Define to be the angle with and , then
This raised-cosine crosses from negative to positive at
This corresponds to sunrise, and it crosses from positive to negative at
And this corresponds to sunset.
Therefore, the angle swing between sunrise and sunset is given by
Since changes linearly with time, and since it covers in hours (this is called a stellar day), it follows that the length of the day is given by
Using the expressions for , and simplifying, results in
As an example, to compute the day length, in Ottawa, on December 13th, compute angle from the number of days that have passed since June 21st, and this number is 175 days. Hence
And since Ottawa has a latitude of North of the Equator, then
Substituting these values in the above equation, and performing the numeric calculations, results in
That is, 8 Hours, and 32 Minutes.
The actual Sunrise in Ottawa was at 7:34 am and Sunset is at 4:20 pm, making the day length = 16:20 - 7:34 = 15:80 - 7:34 = 8:46 , i.e. 8 Hours and 46 minutes.
The difference (about 14 minutes, i.e. error) is due to factors we've ignored like refractions of the sun rays in the atmosphere, and also that our calculation assumes a fixed angle .