-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_functions.py
More file actions
82 lines (65 loc) · 3.83 KB
/
Copy pathplot_functions.py
File metadata and controls
82 lines (65 loc) · 3.83 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import numpy as np
import matplotlib.pyplot as plt
from plot_constants import point_info, res , xy_bound
from physics_functions import z
from numpy.ma import masked_where
# STORING ALL THE FUNCTIONS RELATED TO THE PLOT
# Functions to update the collision markers after a ball/wall collision has occurred
def ball_marker_update(ball_collision_markers):
# Get the collision points
collisions_x, collisions_y = ball_collision_markers.real, ball_collision_markers.imag
# Create the scatter points on the current axis (can't get them as a parameter due to Python addressing issues)
return plt.gcf().get_axes()[0].scatter(collisions_x,collisions_y, z(collisions_x, collisions_y),
c=point_info["marker colour"][0],
s=point_info["size"][0],
marker=point_info["marker"][0],
label=point_info["label"][0])
def wall_marker_update(boundary_collision_markers):
# Get the collision points
collision_x,collision_y = boundary_collision_markers.real, boundary_collision_markers.imag
# Create the scatter points on the current axis (can't get them as a parameter due to Python addressing issues)
return plt.gcf().get_axes()[0].scatter(collision_x,collision_y,z(collision_x,collision_y),
c=point_info["marker colour"][1],
s=point_info["size"][1],
marker=point_info["marker"][1],
label=point_info["label"][1])
# Create the cylinder that extends/wraps around the main funnel suface.
def create_cylinder(X,Y,Z):
# Get the current axis to place the cylinder around
ax = plt.gca()
# Get the bottom and top of the cylinder - make them extend beyond the min and max to make it look more
# realistic to the shape of the original black hole simulator in the Space Centre
bottom = Z.min()-2
top = Z.max() + 0.25
# I have no idea how this code works, I just copied it from chatGPT
theta = np.linspace(0, 2 * np.pi, res)
z_c = np.linspace(bottom, top, 100)
theta, z_c = np.meshgrid(theta, z_c)
# Ditto as above
x_c = xy_bound*np.cos(theta)
y_c = xy_bound*np.sin(theta)
# This code I do understand. Create the plane at the bottom of the plot, then only show the points
# within the cylinder to create the filled circle
cylinder_bottom = masked_where(X**2 + Y**2 > xy_bound**2 + 0.48 , np.ones_like(X)*bottom )
# Plot the bottom of the cylinder
ax.plot_surface(X,Y,cylinder_bottom, color="violet" , alpha=0.45)
# Plot the surface of the cylinder
ax.plot_surface(x_c, y_c, z_c, color="violet", alpha=0.45)
def prepare_KE_ax(KE_ax, fps, t):
KE_ax.set_xlim([0, t+1])
revised_xlabels = np.round( KE_ax.get_xticks() / fps, decimals=2)
KE_ax.set_xticks(KE_ax.get_xticks())
KE_ax.set_xticklabels(revised_xlabels)
KE_ax.set_title("Ball kinetic energy over time")
KE_ax.set_xlabel("Time (s)")
KE_ax.set_ylabel("Kinetic energy (J)")
KE_ax.set_ylim(0)
def prepare_energy_ax(total_energy_ax, fps, t):
total_energy_ax.set_xlim([0,t+1])
revised_xlabels = np.round( total_energy_ax.get_xticks() / fps, decimals=2)
total_energy_ax.set_xticks(total_energy_ax.get_xticks())
total_energy_ax.set_xticklabels(revised_xlabels)
total_energy_ax.set_title("Total system energy over time")
total_energy_ax.set_xlabel("Time (s)")
total_energy_ax.set_ylabel("Total energy (J)")
total_energy_ax.set_ylim(0)