File size: 5,215 Bytes
ea0f98a
11c9a4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c31388a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11c9a4e
 
 
 
 
 
 
 
 
 
 
 
 
 
ea0f98a
c31388a
 
 
 
11c9a4e
 
 
052994c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Import libraries
import math
import numpy as np
import matplotlib.pyplot as plt
import gradio as gr

# Constants
G = 6.67430e-11      # Gravitational constant (m^3 kg^-1 s^-2)
parsec = 3.0857e16   # One parsec in meters
kpc_in_meters = 1e3 * parsec  # One kiloparsec in meters
M_sun = 1.98847e30   # Mass of the sun in kg

# Function to calculate gravitational force between two masses
def gravitational_force(m1, m2, r):
    return G * m1 * m2 / r**2

# Function to convert galactic coordinates to Cartesian coordinates
def galactic_to_cartesian(l, b, R):
    # Convert angles from degrees to radians
    l_rad = np.radians(l)
    b_rad = np.radians(b)
    x = R * np.cos(b_rad) * np.cos(l_rad)
    y = R * np.cos(b_rad) * np.sin(l_rad)
    z = R * np.sin(b_rad)
    return x, y, z

# Function to run the simulation and generate plots
def run_simulation(mass, l1, b1, l2, b2):
    # Fixed parameters
    travel_time = 5  # Travel time in seconds
    R = 8.2 * kpc_in_meters  # Distance from Galactic center to the object in meters

    # Mass of the black hole (Sagittarius A*)
    black_hole_mass = 4e6 * M_sun  # Mass of Sagittarius A*

    # Convert galactic coordinates to Cartesian coordinates
    x1, y1, z1 = galactic_to_cartesian(l1, b1, R)
    x2, y2, z2 = galactic_to_cartesian(l2, b2, R)

    # Calculate distance between starting and ending points
    dx_total = x2 - x1
    dy_total = y2 - y1
    dz_total = z2 - z1
    distance = np.sqrt(dx_total**2 + dy_total**2 + dz_total**2)

    # Calculate required velocity components
    velocity_x = dx_total / travel_time
    velocity_y = dy_total / travel_time
    velocity_z = dz_total / travel_time
    velocity_magnitude = np.sqrt(velocity_x**2 + velocity_y**2 + velocity_z**2)

    # Time array
    time_steps = np.linspace(0, travel_time, num=100)

    # Initialize arrays for position, velocity, and force
    x_positions = x1 + velocity_x * time_steps
    y_positions = y1 + velocity_y * time_steps
    z_positions = z1 + velocity_z * time_steps
    positions = np.sqrt(x_positions**2 + y_positions**2 + z_positions**2)

    # Calculate gravitational force at each time step
    forces = gravitational_force(mass, black_hole_mass, positions)

    # Plotting the variables over time
    fig, axs = plt.subplots(3, 1, figsize=(12, 8))

    # Position Plot
    axs[0].plot(time_steps, positions / parsec, label='Distance from Galactic Center')
    axs[0].set_ylabel('Distance (parsecs)')
    axs[0].set_title('Object Position Over Time')
    axs[0].legend()

    # Velocity Plot (constant in this case)
    axs[1].plot(time_steps, [velocity_magnitude]*len(time_steps), label='Velocity', color='orange')
    axs[1].set_ylabel('Velocity (m/s)')
    axs[1].set_title('Object Velocity Over Time')
    axs[1].legend()

    # Gravitational Force Plot
    axs[2].plot(time_steps, forces, label='Gravitational Force', color='green')
    axs[2].set_xlabel('Time (s)')
    axs[2].set_ylabel('Force (N)')
    axs[2].set_title('Gravitational Force Over Time')
    axs[2].legend()

    plt.tight_layout()

    # Return the required velocity and the plot figure
    required_velocity_str = f"Required Velocity: {velocity_magnitude:.2e} m/s"
    return required_velocity_str, fig

# Physics equations in LaTeX format
physics_equations = r"""
### Physics Equations Used:

1. **Gravitational Force:**

   $$ F = \frac{G \cdot m_1 \cdot m_2}{r^2} $$

   - \( F \): Gravitational force (N)
   - \( G \): Gravitational constant (\(6.67430 \times 10^{-11}\) m\(^3\) kg\(^{-1}\) s\(^{-2}\))
   - \( m_1, m_2 \): Masses of the objects (kg)
   - \( r \): Distance between the centers of the two masses (m)

2. **Required Velocity:**

   $$ v = \frac{d}{t} $$

   - \( v \): Velocity (m/s)
   - \( d \): Distance traveled (m)
   - \( t \): Time taken (s)

3. **Distance Between Two Points in 3D Space:**

   $$ d = \sqrt{ (x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2 } $$

   - \( (x_1, y_1, z_1) \): Coordinates of the starting point
   - \( (x_2, y_2, z_2) \): Coordinates of the ending point

4. **Conversion from Galactic Coordinates to Cartesian Coordinates:**

   $$ \begin{aligned}
   x &= R \cos b \cos l \\
   y &= R \cos b \sin l \\
   z &= R \sin b
   \end{aligned} $$

   - \( l \): Galactic longitude (radians)
   - \( b \): Galactic latitude (radians)
   - \( R \): Distance from the Galactic center (m)
"""

# Define the Gradio interface
interface = gr.Interface(
    fn=run_simulation,
    inputs=[
        gr.Number(value=1e5, label="Mass of the object (kg)"),
        gr.Number(value=0, label="Starting Galactic Longitude (degrees)"),
        gr.Number(value=0, label="Starting Galactic Latitude (degrees)"),
        gr.Number(value=10, label="Ending Galactic Longitude (degrees)"),
        gr.Number(value=5, label="Ending Galactic Latitude (degrees)")
    ],
    outputs=[
        gr.Textbox(label="Required Velocity"),
        gr.Plot(label="Simulation Plots")
    ],
    title="AI of DornHai Bracelets (Inspired by Taklee Genesis film)",
    description=(
        "Simulate variables during interstellar travel with advanced technology.\n\n"
        + physics_equations
    )
)

# Launch the interface
if __name__ == "__main__":
    interface.launch()