forked from Nate534/black_hole
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_with_matplotlib.py
More file actions
60 lines (49 loc) · 1.63 KB
/
Copy pathcheck_with_matplotlib.py
File metadata and controls
60 lines (49 loc) · 1.63 KB
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
import sys
sys.path.insert(0, 'src')
import matplotlib.pyplot as plt
import numpy as np
from physics.black_hole import BlackHole
from physics.particle import ParticleSystem
from physics.constants import G
# Create black hole
black_hole = BlackHole(mass=4e37, position=(0, 0, 0))
# Create particle system
particle_system = ParticleSystem()
# Add some particles for testing
num_particles = 10
inner_radius = black_hole.schwarz_radius * 2.5
outer_radius = black_hole.schwarz_radius * 12
for i in range(num_particles):
distance = np.random.uniform(inner_radius, outer_radius)
angle = np.random.uniform(0, 2 * np.pi)
x = distance * np.cos(angle)
z = distance * np.sin(angle)
y = np.random.uniform(-outer_radius/50, outer_radius/50)
orbital_speed = np.sqrt(G * black_hole.mass / distance)
vx = -orbital_speed * np.sin(angle)
vz = orbital_speed * np.cos(angle)
particle_system.add_particle(
mass=np.random.uniform(1e9, 1e10),
position=(x, y, z),
velocity=(vx, 0, vz),
colour=(1, 0, 0)
)
# Update a few times
for _ in range(10):
particle_system.update(black_hole, 50.0)
# Plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Plot black hole
ax.scatter(0, 0, 0, color='black', s=100, label='Black Hole')
# Plot particles
for particle in particle_system.particles:
ax.scatter(particle.position[0], particle.position[1], particle.position[2],
color=particle.colour, s=10)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.legend()
plt.title('Black Hole Simulation Positions')
plt.savefig('simulation.png')
print("Plot saved to simulation.png")