Ravel Simulator (Exploring Near-Light-Speed Physics with Python)

 ravel Simulator

(Exploring Near-Light-Speed Physics with Python Code)


Relativistic Space Travel Simulator

(Exploring Near-Light-Speed Physics with Python)


This simulation models time dilation, length contraction, and energy requirements for near-light-speed travel using Einstein's Special Relativity.  

---

🚀 Key Physics Equations

Lorentz Factor (γ)

   \[

   \gamma = \frac{1}{\sqrt{1 - \frac{v^2}{c^2}}

   \]  

2. Time Dilation

   \[

   \Delta t' = \gamma \Delta t

   \]  

3. Length Contraction  

   \[

   L' = \frac{L}{\gamma}

   \]  

4. Relativistic Kinetic Energy

   \[

   E_k = (\gamma - 1)mc^2

   \]  


---


💻 Python Simulation Code


```python

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.widgets import Slider


# Constants

c = 299792458  # Speed of light (m/s)

year_sec = 31536000  # Seconds in a year


def lorentz_factor(v):

    """Calculate the Lorentz factor γ for velocity v."""

    return 1 / np.sqrt(1 - (v**2 / c**2))


def simulate_relativity(v_fraction):

    """

    Simulate relativistic effects at a given fraction of light speed.

    Args:

        v_fraction (float): Fraction of light speed (0 < v < 1).

    Returns:

        dict: Time dilation, length contraction, and energy ratios.

    """

    v = v_fraction * c

    gamma = lorentz_factor(v)

    

    # Time dilation (1 year onboard)

    t_earth = gamma * 1  # Earth time (years)

    

    # Length contraction (1 light-year distance)

    L_contract = 1 / gamma  # Contracted distance (light-years)

    

    # Energy (for 1000kg spacecraft)

    m = 1000  # kg

    E_k = (gamma - 1) * m * (c**2)  # Kinetic energy (Joules)

    E_k_equivalent = E_k / (1e19)  # Equivalent in "Jupiter masses" (simplified)

    

    return {

        "velocity": v,

        "gamma": gamma,

        "time_dilation": t_earth,

        "length_contraction": L_contract,

        "energy_joules": E_k,

        "energy_jupiter_masses": E_k_equivalent

    }


# Interactive Plot

fig, ax = plt.subplots(3, 1, figsize=(10, 8))

plt.subplots_adjust(bottom=0.25)


# Slider for velocity

ax_slider = plt.axes([0.2, 0.1, 0.6, 0.03])

slider = Slider(ax_slider, 'Velocity (% of c)', 0.01, 0.99, valinit=0.5)


# Update function

def update(val):

    v_fraction = slider.val

    data = simulate_relativity(v_fraction)

    

    # Clear previous plots

    for a in ax:

        a.clear()

    

    # Plot 1: Time Dilation

    ax[0].set_title(f"Time Dilation: 1 year onboard = {data['time_dilation']:.2f} years on Earth")

    ax[0].bar(['Onboard', 'Earth'], [1, data['time_dilation']], color=['blue', 'red'])

    

    # Plot 2: Length Contraction

    ax[1].set_title(f"Length Contraction: 1 light-year becomes {data['length_contraction']:.4f} light-years")

    ax[1].bar(['Original', 'Contracted'], [1, data['length_contraction']], color=['green', 'orange'])

    

    # Plot 3: Energy Requirements

    ax[2].set_title(f"Energy Required: {data['energy_joules']:.2e} J (≈{data['energy_jupiter_masses']:.2f}× Jupiter's mass energy)")

    ax[2].text(0.5, 0.5, f"γ (Lorentz Factor) = {data['gamma']:.2f}", ha='center', va='center', fontsize=12)

    

    plt.draw()


slider.on_changed(update)

update(0.5)  # Initialize

plt.show()

```


---


📊 What This Simulates  

1. Time Dilation 

   - At 90% light speed, 1 year for the traveler = 2.29 years on Earth.  

   - At 99% light speed, 1 year onboard ≈ 7 years on Earth.  


2. Length Contraction

   - A 1-light-year distance shrinks to 0.14 light-years** at 99% *c*.  


3. Energy Requirements 

   - Accelerating 1 ton (1000kg) to 90% c requires ≈10²⁰ Joules (~1,000x global annual energy output).  


---


🔮 Extending the Simulation

- Add acceleration effects (constant 1g thrust).  

- Model relativistic Doppler shifts (how stars look at near-c).  

- Simulate warp-drive metrics (Alcubierre solution).  


Would you like these extensions? Let me know how deep you want to go! 🚀

Post a Comment

Previous Next

نموذج الاتصال