Sunlight on Mercator Map

A Mercator Projection maps a point on the earth's surface with longititude θ (degrees, positive for east of Greenwich) and latitude λ (degrees, -90<= λ <=90, positive for the northern hemisphere) to a rectangle in such a way that 

Recall that the usual spherical coords (r, θ, ϕ) use r=radius of earth,  θ = longitude, ϕ = colatitude, so that ϕ = 90-λ.

Relation between {x,y,z} rectangular coordinates of a unit vector and {θ,λ}: (not quite standard spherical polar coords.)

x = Cos[λ] Cos[θ]
y = Cos[λ] Sin[θ]
z = Sin[λ]

torect[{θ_, λ_}]:={Cos[λ Degree] Cos[θ Degree], Cos[λ Degree] Sin[θ Degree], Sin[λ Degree]}

\(topolar[{x_, y_, z_}] := 

      	{If[x == 0 && y == 0, 0, ArcTan[x, y]/Degree], ArcSin[z]/Degree}\)

We now need to work out the great circle trajectory on the Mercator map corresponding to the edge of the sunlit zone when the sun is overhead at location (θ,λ). Given points A, B, the unit vectors a, b in their respective  directions may not be perpendicular, but if they are, the circle from A to B is given in terms of angle w as parameter by

c=Cos[w] a + Sin[w] b

Pick out one vector on edge of sunlit zone. If λ>0, use A={θ+180,90-λ), else A=(θ,λ+90). Then take B perp to both A and the sun to get other edge.

sunlitpts[θ_, λ_]:=  
	Module[{A, B, i},A = torect[
                If[λ >= 0, {θ + 180, 90 - λ}, {
                    θ, λ + 90}]]; B = A\[Cross]torect[{θ, λ}];
		Table[Round[
                  60 topolar[Cos[i Degree] A + Sin[i Degree] B]], {i, 0, 
                  360, 5}]   
	]

sunlitpts[-117, 23.5]

ListPlot[sunlitpts[-117, 23.5]/60]

We'll modify this to indicate on a Mercator map of the world the sun's position and the edge of the sunlit area. For this, we use worldplot, where the units are minutes rather than degrees, requiring us to rescale everything by 60. We also need to rotate the worldplot using the WorldRotation option to make the sun's longitude centered. Handle this by WorldRotation-> {0,0,-θ}.

Needs["Miscellaneous`WorldPlot`"]

Clear[plotsunlit]

plotsunlit[θ_, λ_]:=  
	Module[{edge = sunlitpts[θ, λ], wmap},
      wmap=WorldPlot[World,
          WorldBackground  ->  
                        RGBColor[0.240,  1.000,  1.000],
          WorldGrid  -> 30,
          WorldFrame  ->  Thickness[0.004],
	WorldFrameParts  ->  {0, 1, 0, 1},
			 WorldRange  -> {{-80, 80}, {-180, 180}},
          WorldRotation ->  {0, 0, - θ},
				WorldProjection  ->  Mercator    
			];  
			\(Show[{
						wmap, 
						\ 
                  WorldGraphics[

                    							{RGBColor[1, 1, 0], PointSize[ .05], 

                      						
                      Point[{60\ λ, 60\ θ}],  (*sun*) 

                      						RGBColor[1, 0, 0], 
								
                      PointSize[ .01], 

                      							 (*Map[Point, Map[Reverse, edge]]*) 

                      							Line[Map[Reverse, edge]]}
						]

                  					}]\)   
	]

plotsunlit[-117, 23.5]

\(\(animatedsunlit[θ_] :=  (*give\ longitude\ in\ degrees*) 
	
      Module[{edge, wmap}, 
\ \ \ \ \ \ 
        wmap = WorldPlot[World, 
\ \ \ \ \ \ \ \ \ \ 
            WorldBackground\  -> \ RGBColor[0.240, \ 1.000, \ 1.000], 

            \ \ \ \ \ \ \ \ \ \ WorldGrid\  -> 30, 
\ \ \ \ \ \ \ \ \ \ 
            WorldFrame\  -> \ Thickness[0.004], 
	
            WorldFrameParts\  -> \ {0, 1, 0, 1}, 
			\ 
            WorldRange\  -> {{\(-80\), 80}, {\(-180\), 180}}, 

            \ \ \ \ \ \ \ \ \ \ WorldRotation -> \ {0, 0, \(-\ θ\)}, 

            				WorldProjection\  -> \ Mercator\ \  (*
              generate\ background\ map*) 
			];  (*end\ wmap*) 
			
        \(Do[
			λ = 23.5\ Sin[2\ Pi\ k/12]; 
						
            edge = sunlitpts[θ, λ]; 
					
            Show[{
						wmap, 
						\ 
                WorldGraphics[

                  							{RGBColor[1, 1, 0], PointSize[ .05], 

                    						
                    Point[{60\ λ, 60\ θ}],  (*sun*) 

                    						RGBColor[1, 0, 0], 
								
                    PointSize[ .01], 

                    							 (*Map[Point, Map[Reverse, edge]]*) 

                    							Line[Map[Reverse, edge]]}
						]

                					}], \  (*end\ Show*) 
			{k, 0, 11}]\ \) (*
          end\ Do*) 
	] (*end\ Module*) \)\)

animatedsunlit[-117]