% Plot initial position of Earth on its orbit as a blue circle
h_earthPosition=plot3(Xearth_AU(1,1),Xearth_AU(2,1),Xearth_AU(3,1),'bo','MarkerFaceColor','none','Color','blue','DisplayName',sprintf('Earth Initial Position on %s',StartDate));
% Plot final position of Earth on its orbit as a filled blue circle
h_earthFinal=plot3(Xearth_AU(1,end),Xearth_AU(2,end),Xearth_AU(3,end),'bo','MarkerFaceColor','blue','DisplayName',sprintf('Earth Final Position on %s',EndDate));
% Plot Mars' orbit in Astronomical Units (AU) as a red line
% Plot initial position of Mars on its orbit as a red circle
h_marsPosition=plot3(Xmars_AU(1,1),Xmars_AU(2,1),Xmars_AU(3,1),'ro','MarkerFaceColor','none','Color','red','DisplayName',sprintf('Mars Initial Position on %s',StartDate));
% Plot final position of Mars on its orbit as a filled red circle
h_marsFinal=plot3(Xmars_AU(1,end),Xmars_AU(2,end),Xmars_AU(3,end),'ro','MarkerFaceColor','red','DisplayName',sprintf('Mars Final Position on %s',EndDate));
% Plot the Sun at the origin of the coordinate system as a yellow filled circle
title(sprintf('3D Orbit Trajectories of Earth and Mars from %s to %s',StartDate,EndDate));% Title of the plot
legend([h_earthOrbit,h_earthPosition,h_earthFinal,h_marsOrbit,h_marsPosition,h_marsFinal,h_sun],'Location','bestoutside');% Legend to identify plot elements
gridon;% Enable grid for better visualization
axisequal;% Equal scaling for all axes
xlim([-2,2]);% X-axis limits
ylim([-2,2]);% Y-axis limits
zlim([-2,2]);% Z-axis limits
view(3);% Set the view to 3D perspective
%% Top Down View
% Create a new figure for the top-down plot
figure();
% Plot Earth's orbit in Astronomical Units (AU) as a blue line
% Plot initial position of Earth on its orbit as a blue circle
h_earthPosition=plot3(Xearth_AU(1,1),Xearth_AU(2,1),Xearth_AU(3,1),'bo','MarkerFaceColor','none','Color','blue','DisplayName',sprintf('Earth Initial Position on %s',StartDate));
% Plot final position of Earth on its orbit as a filled blue circle
h_earthFinal=plot3(Xearth_AU(1,end),Xearth_AU(2,end),Xearth_AU(3,end),'bo','MarkerFaceColor','blue','DisplayName',sprintf('Earth Final Position on %s',EndDate));
% Plot Mars' orbit in Astronomical Units (AU) as a red line
% Plot initial position of Mars on its orbit as a red circle
h_marsPosition=plot3(Xmars_AU(1,1),Xmars_AU(2,1),Xmars_AU(3,1),'ro','MarkerFaceColor','none','Color','red','DisplayName',sprintf('Mars Initial Position on %s',StartDate));
% Plot final position of Mars on its orbit as a filled red circle
h_marsFinal=plot3(Xmars_AU(1,end),Xmars_AU(2,end),Xmars_AU(3,end),'ro','MarkerFaceColor','red','DisplayName',sprintf('Mars Final Position on %s',EndDate));
% Plot the Sun at the origin of the coordinate system as a yellow filled circle
% Enhancements for 3D Visualization in a 2D projection
xlabel('X Distance (AU)');% Label for the X-axis
ylabel('Y Distance (AU)');% Label for the Y-axis
zlabel('Z Distance (AU)');% Label for the Z-axis (though not visible in top-down view)
title(sprintf('3D Orbit Trajectories of Earth and Mars from %s to %s',StartDate,EndDate));% Title of the plot
legend([h_earthOrbit,h_earthPosition,h_earthFinal,h_marsOrbit,h_marsPosition,h_marsFinal,h_sun],'Location','bestoutside');% Legend to identify plot elements
gridon;% Enable grid for better visualization
axisequal;% Equal scaling for all axes
xlim([-2,2]);% X-axis limits
ylim([-2,2]);% Y-axis limits
zlim([-2,2]);% Z-axis limits (mostly for maintaining aspect ratio)
view(0,90);% Set the view to top-down (along the z-axis)
%% Top Down View
% Create a new figure for the top-down plot
figure();
% Plot Earth's orbit in Astronomical Units (AU) as a blue line
% Plot initial position of Earth on its orbit as a blue circle
h_earthPosition=plot3(Xearth_AU(1,1),Xearth_AU(2,1),Xearth_AU(3,1),'bo','MarkerFaceColor','none','Color','blue','DisplayName',sprintf('Earth Initial Position on %s',StartDate));
% Plot final position of Earth on its orbit as a filled blue circle
h_earthFinal=plot3(Xearth_AU(1,end),Xearth_AU(2,end),Xearth_AU(3,end),'bo','MarkerFaceColor','blue','DisplayName',sprintf('Earth Final Position on %s',EndDate));
% Plot Mars' orbit in Astronomical Units (AU) as a red line
% Plot initial position of Mars on its orbit as a red circle
h_marsPosition=plot3(Xmars_AU(1,1),Xmars_AU(2,1),Xmars_AU(3,1),'ro','MarkerFaceColor','none','Color','red','DisplayName',sprintf('Mars Initial Position on %s',StartDate));
% Plot final position of Mars on its orbit as a filled red circle
h_marsFinal=plot3(Xmars_AU(1,end),Xmars_AU(2,end),Xmars_AU(3,end),'ro','MarkerFaceColor','red','DisplayName',sprintf('Mars Final Position on %s',EndDate));
% Plot the Sun at the origin of the coordinate system as a yellow filled circle
% Enhancements for 3D Visualization in a 2D projection
xlabel('X Distance (AU)');% Label for the X-axis
ylabel('Y Distance (AU)');% Label for the Y-axis
zlabel('Z Distance (AU)');% Label for the Z-axis (though not visible in top-down view)
title(sprintf('3D Orbit Trajectories of Earth and Mars from %s to %s',StartDate,EndDate));% Title of the plot
legend([h_earthOrbit,h_earthPosition,h_earthFinal,h_marsOrbit,h_marsPosition,h_marsFinal,h_sun],'Location','bestoutside');% Legend to identify plot elements
gridon;% Enable grid for better visualization
axisequal;% Equal scaling for all axes
xlim([-2,2]);% X-axis limits
ylim([-2,2]);% Y-axis limits
zlim([-2,2]);% Z-axis limits (mostly for maintaining aspect ratio)
view(0,0);% Set the view to top-down (along the z-axis)
%% Clean up by unloading SPICE kernels
cspice_kclear;% Unload all SPICE kernels and clear the SPICE subsystem