Git Product home page Git Product logo

thomasafink / visualization_of_the_solar_system_on_an_interstellar_scale Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 177.28 MB

Visualize the Solar System: A Python script that plots the orbits of the major planets, with a special focus on Pluto and the Kuiper Belt. Utilizing NumPy for calculations and Matplotlib for visualization, this script provides an educational tool to explore the dynamics of our solar system, highlighting Pluto's unique orbit and the vast Kuiper Belt

License: MIT License

Python 100.00%
astronomy kuiper-belt nasa orbit pluto python solar solar-system system alpha-centauri greeks oort-cloud proxima-centauri scale trojans hildas astro astrophysics installer oumuamua

visualization_of_the_solar_system_on_an_interstellar_scale's Introduction

Visualization of The Solar System on an Interstellar Scale

This Python script provides a detailed visualization of the orbital paths of the major planets in our solar system, with a special focus on Pluto and its relationship with the Kuiper Belt. Utilizing numpy for mathematical calculations and matplotlib for plotting, the script generates a comprehensive diagram showing the orbits of the planets, Pluto's elliptical orbit, and the scattered distribution of the Kuiper Belt.

Inner Solar System With Jupiter Solar System With Kuiper Belt
Inner Solar System With Jupiter Solar System With Kuiper Belt
Solar System With Oort Cloud Solar System with Alpha Centauri
Solar System With Oort Cloud Solar System with Alpha Centauri
Interstellar Neighbors Within 10 Light Years Interstellar Neighbors Within 25 Light Years
Interstellar Neighbors Within 10 Light Years Interstellar Neighbors Within 25 Light Years

Getting Started

To run this script, you need Python installed on your system along with the numpy and matplotlib libraries. These dependencies can be installed using pip:

pip3 install numpy
pip3 install pandas
pip3 install matplotlib
pip3 install mpl_toolkits

Code Explanation

Importing Libraries

import re
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

Constants Definition

These constants define various parameters for the orbits of the major planets, Pluto, and the various asteroid belts. The semi-major axes of the planet orbits and specific parameters related to Pluto's orbit and the Kuiper Belt are set here.

ORBIT_POINTS = 1000
PLANET_ORBITS = [0.39, 0.72, 1.0, 1.52, 5.2, 9.5, 19.2, 30]
PLUTO_PERIHELION = 29.7
PLUTO_APHELION = 49.5
PLUTO_ECCENTRICITY = 0.25
PLUTO_SEMI_MAJOR_AXIS = (PLUTO_PERIHELION + PLUTO_APHELION) / 2
KUIPER_BELT_INNER = 30
KUIPER_BELT_OUTER = 50
ASTEROID_BELT_INNER = 2.2
ASTEROID_BELT_OUTER = 3.2
JUPITER_SEMI_MAJOR_AXIS = 5.2
JUPITER_INCLINATION = 1.3
JUPITER_ECCENTRICITY = 0.0489
TROJANS_GREEKS_ANGLE = np.deg2rad(60)
TROJANS_GREEKS_SPREAD = np.pi / 3
TROJANS_GREEKS_WIDTH = 0.5
HILDAS_INNER = ASTEROID_BELT_OUTER+0.25
HILDAS_OUTER = JUPITER_SEMI_MAJOR_AXIS-0.25
OORT_CLOUD_INNER = 2000
OORT_CLOUD_OUTER = 100000

if limit[3] == 'inner_solar_system':
    ASTEROID_BELT_POINTS = 20000
    TROJANS_GREEKS_POINTS = 4000
    HILDAS_POINTS = 4000
    KUIPER_BELT_POINTS = 10000
    OORT_CLOUD_POINTS = 50000

elif limit[3] == 'inner_solar_system_with_jupiter':
    ASTEROID_BELT_POINTS = 10000
    TROJANS_GREEKS_POINTS = 2000
    HILDAS_POINTS = 2000
    KUIPER_BELT_POINTS = 10000
    OORT_CLOUD_POINTS = 50000

elif limit[3] == 'solar_system_with_kuiper_belt':
    ASTEROID_BELT_POINTS = 100
    TROJANS_GREEKS_POINTS = 10
    HILDAS_POINTS = 100
    KUIPER_BELT_POINTS = 10000
    OORT_CLOUD_POINTS = 50000

elif limit[3] == 'solar_system_with_oort_cloud':
    ASTEROID_BELT_POINTS = 20
    TROJANS_GREEKS_POINTS = 10
    HILDAS_POINTS = 10
    KUIPER_BELT_POINTS = 100
    OORT_CLOUD_POINTS = 50000

elif limit[3] == 'solar_system_with_alpha_centauri':
    ASTEROID_BELT_POINTS = 10
    TROJANS_GREEKS_POINTS = 5
    HILDAS_POINTS = 5
    KUIPER_BELT_POINTS = 50
    OORT_CLOUD_POINTS = 5000  

elif  limit[3] == 'solar_system_with_nearest_stars_10':
    ASTEROID_BELT_POINTS = 2
    TROJANS_GREEKS_POINTS = 2
    HILDAS_POINTS = 2
    KUIPER_BELT_POINTS = 20
    OORT_CLOUD_POINTS = 2000

elif  limit[3] == 'solar_system_with_nearest_stars_25':
    ASTEROID_BELT_POINTS = 1
    TROJANS_GREEKS_POINTS = 1
    HILDAS_POINTS = 1
    KUIPER_BELT_POINTS = 10
    OORT_CLOUD_POINTS = 1000

Function to Calculate Ellipse

This function calculates the x and y coordinates for points on an ellipse, used to plot Pluto's orbit. It takes the eccentricity and semi-major axis of the ellipse, along with an array of angle values (theta), to compute the coordinates.

Equation 1: Calculates the semi-minor axis (b) of the ellipse based on its semi-major axis (a) and eccentricity (ε). The eccentricity measures the deviation of the ellipse from a perfect circle, with 0 representing a circle. The semi-minor axis is derived using the relationship between the eccentricity and the semi-major axis.

  • Equation 1

Equation 2: Computes the radial distance (r) from the center of the ellipse to a point on its edge, given an angle (theta) from the major axis. This formula adjusts for the ellipse's eccentricity, which influences the radial distance across the ellipse.

  • Equation 2

Equation 3: Determines the x-coordinate of a point on the ellipse, based on the radial distance (r) and the angle (theta), showing how this distance is projected onto the x-axis.

  • Equation 3

Equation 4: Calculates the y-coordinate of a point on the ellipse, using the radial distance (r) and the angle (theta), which illustrates the projection of this distance onto the y-axis.

  • Equation 4
def calculate_ellipse(eccentricity, semi_major_axis, theta):
    """
    Calculate the x, y coordinates of an ellipse based on eccentricity and semi-major axis.
    """
    b = semi_major_axis * np.sqrt(1 - eccentricity**2)  # Semi-minor axis
    r = (semi_major_axis * (1 - eccentricity**2)) / (1 + eccentricity * np.cos(theta))
    x = r * np.cos(theta)
    y = r * np.sin(theta)
    return x, y

Generating Orbits and Kuiper Belt

Generates the coordinates for Pluto's orbit and randomly distributed points within the Kuiper Belt. For Pluto, it calculates an elliptical orbit. For the Kuiper Belt, it generates points within specified radial distances to simulate its scattered disk.

theta = np.linspace(0, 2 * np.pi, ORBIT_POINTS)
x, y = calculate_ellipse(PLUTO_ECCENTRICITY, PLUTO_SEMI_MAJOR_AXIS, theta)

kuiper_belt_r = np.random.uniform(KUIPER_BELT_INNER, KUIPER_BELT_OUTER, KUIPER_BELT_POINTS)
kuiper_belt_theta = np.random.uniform(0, 2 * np.pi, KUIPER_BELT_POINTS)
kuiper_belt_x = kuiper_belt_r * np.cos(kuiper_belt_theta)
kuiper_belt_y = kuiper_belt_r * np.sin(kuiper_belt_theta)

Plotting

fig, ax = plt.subplots(figsize=(39, 39))

Plots the Sun at the center of the solar system.

# Plot the Sun at the center
sun = plt.Circle((0, 0), 0.05, color='yellow', fill=True)
ax.add_artist(sun)

Loops through the PLANET_ORBITS array to plot circular orbits for each of the major planets.

# Plot the orbits of the major planets
for orbit in PLANET_ORBITS:
    circle = plt.Circle((0, 0), orbit, color='black', fill=False)
    ax.add_artist(circle)

Plots Pluto's elliptical orbit and scatters points for the Kuiper Belt.

# Plot the elliptical orbit of Pluto
ax.plot(x, y, color='blue')

# Mark the perihelion and aphelion of Pluto's orbit
ax.plot(PLUTO_PERIHELION, 0, 'bo')  # Perihelion
ax.plot(-PLUTO_APHELION, 0, 'bo')  # Aphelion

# Scatter the adjusted points for the Kuiper Belt
ax.scatter(kuiper_belt_x, kuiper_belt_y, color='gray', s=5)

Adds annotations for key features such as Pluto's perihelion and aphelion, and labels the Kuiper Belt. It also adjusts the plot's appearance for better visualization.

# Annotations and labels with increased font size
font_size = 48
ax.annotate('Kuiper Belt', xy=(KUIPER_BELT_OUTER, 0), xytext=(KUIPER_BELT_OUTER+5, 10),
            arrowprops=dict(facecolor='black', shrink=0.05), fontsize=font_size)
ax.annotate("Pluto's aphelion (49.5 AU)", xy=(-PLUTO_APHELION, 0), xytext=(-PLUTO_APHELION-25, 10),
            arrowprops=dict(facecolor='black', shrink=0.05), fontsize=font_size)
ax.annotate("Pluto's perihelion (29.7 AU)", xy=(PLUTO_PERIHELION, 0), xytext=(PLUTO_PERIHELION+10, -10),
            arrowprops=dict(facecolor='black', shrink=0.05), fontsize=font_size)

Saves the generated plot as a high-resolution image for use in presentations, educational materials, or personal study.

ax.set_xlim([-70, 70])
ax.set_ylim([-70, 70])
ax.set_aspect('equal', 'box')
ax.axis('off')
plt.title('Relationship of Pluto’s orbit to the Kuiper Belt', fontsize=62)
plt.savefig("orbit.jpg", dpi=300)
plt.show()

3D Visualization of Pluto's Orbit and the Kuiper Belt

The following images provide different perspectives on Pluto's orbit and the Kuiper Belt, showcasing the 3D modeling capabilities of matplotlib. These images can be generated from various viewing angles to illustrate the complex spatial relationships within this region of our solar system.

Inner Solar System With Jupiter Solar System With Kuiper Belt
Inner Solar System With Jupiter Solar System With Kuiper Belt
Solar System With Oort Cloud Solar System with Alpha Centauri
Solar System With Oort Cloud Solar System with Alpha Centauri
Interstellar Neighbors Within 10 Light Years Interstellar Neighbors Within 25 Light Years
Interstellar Neighbors Within 10 Light Years Interstellar Neighbors Within 25 Light Years

Conclusion

This script is an educational tool that visualizes the orbits within our solar system, with a focus on Pluto and the Kuiper Belt. It demonstrates the power of numpy and matplotlib in creating complex scientific visualizations. Feel free to modify the constants and functions to explore other celestial mechanics or solar system objects.

visualization_of_the_solar_system_on_an_interstellar_scale's People

Contributors

thomasafink avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.