What Planet Is Cloestest to Earth?



What Planet Is Cloestest to Earth?


Mars or Venus, right? GOTCHA its Mercury. Nearly always. Code below proves it. Deal with it.

Result

This plot gives the distance in astronomical units between the Earth and our nearest planets from 2010 to 2024.


Code

Use code below to generate this plot and above gif animation.

dist[planet_,d1_,d2_]:=PlanetData[planet,Table[EntityProperty["Planet","DistanceFromEarth",{"Date"->DateObject[date]}],{date,DateRange[d1,d2,"Week"]}]]
ts[planet_,d1_,d2_]:=TimeSeries[Transpose[{DateRange[d1,d2,"Week"],dist[planet,d1,d2]}]]

toplot = AssociationMap[ts[#,{2010,0,0},{2024,0,0}]&,{"Mercury","Venus","Mars"(*,"Jupiter","Saturn" *)}];

DateListPlot[toplot,PlotLegends->"Expressions",FrameLabel->Automatic,PlotStyle->{Purple,Orange,Red},Frame->True]

mer=(toplot[[1]]//Normal)[[;;,2]];
venus=(toplot[[2]]//Normal)[[;;,2]];
mars=(toplot[[3]]//Normal)[[;;,2]];
lengthslist = MapThread[{#1,#2,#3}&,{mer,venus,mars}];
closest=PositionSmallest[#]&/@lengthslist;
times =(toplot[[3]]//Normal)[[;;,1]];
lengths=Table[{lengthslist[[i,closest[[i]][[1]]]],closest[[i]][[1]]},{i,Range[Length[times]]}];

list = Flatten[#]&/@Transpose[{times,lengths}];
merclose = Select[list,#[[3]]==1&];
venusclose = Select[list,#[[3]]==2&];
marsclose = Select[list,#[[3]]==3&];

closest=Flatten[Join[{merclose[[;;,{1,2}]],venusclose[[;;,{1,2}]],marsclose[[;;,{1,2}]]}],1];
DateListPlot[closest,Joined->True];



DateListPlot[Append[toplot,{"Mercury Closest"->merclose[[;;,{1,2}]],"Venus Closest"->venusclose[[;;,{1,2}]],"Mars Closest"->marsclose[[;;,{1,2}]]}],PlotLegends->"Expressions",FrameLabel->Automatic,PlotStyle->{Blue,Red,Green},Frame->True,Filling->{4->Bottom,5->Bottom,6->Bottom},PlotRange->{{{2010,1,1},{2023,0,0}},{0,3}},Joined->{True,True,True,False,False,False},PlotMarkers->{None,None,None,None,None,None}]

mercurymap=GeoGraphics[GeoModel->Entity["Planet","Mercury"],GeoRange->All];
venusmap =GeoGraphics[GeoModel->Entity["Planet","Venus"],GeoRange->All];
earthmap =GeoGraphics[GeoModel->Entity["Planet","Earth"],GeoRange->All];
earthmap = GeoImage[{GeoPosition[{-70,180}],GeoPosition[{90,-180}]},GeoRangePadding->None,GeoProjection->"Mercator"];
marsmap =GeoGraphics[GeoModel->Entity["Planet","Mars"],GeoRange->All];

generatesphere[map_,size_]:=Module[{pic,width,height,w,h,sphere},
pic=map;
{width,height}=ImageDimensions[pic];
{w,h} = {35,40};
pic=ImageTake[pic,{h,height-h},{w,width-w}];
sphere=ParametricPlot3D[{Cos[u] Sin[v],Sin[u] Sin[v],Cos[v]},{u,0,2 Pi},{v,0,Pi},Mesh->None,PlotPoints->100,TextureCoordinateFunction->({#4,1-#5}&),Boxed->False,PlotStyle->Texture[Show[pic,ImageSize->1000]],Lighting->"Neutral",Axes->False,RotationAction->"Clip",ViewPoint->{-2.026774,2.07922,1.73753418},ImageSize->600];
Return[sphere];
]

planets = PlanetData[];
time = DateObject[];
planets=planets[[1;;4]]
n=1;
maxn = 356*10; 
plots = Table[0,{i,1,maxn,1}];
size =0.1;
planetpositions=QuantityMagnitude[ UnitConvert[PlanetData[#,EntityProperty["Planet","HelioCoordinates",{"Date"->time}]],"au"]]&/@ planets;
styledplanetspheres ={Scale[generatesphere[mercurymap,1][[1]],size*0.5],Scale[generatesphere[venusmap,1][[1]],size*2],Scale[generatesphere[earthmap,1][[1]],size*2],Scale[generatesphere[marsmap,1][[1]],size]};

locs = MapThread[Translate[#1,#2]&,{styledplanetspheres,planetpositions}];
paths = PlanetData[planets,"OrbitPath"];

Graphics3D[{locs,paths},PlotRange->{{-2,2},{-2,2},{-1/2,1/2}},Axes->False,Boxed->False,ImageSize->Large]