Here's the modified code with the requested changes:
- Doubled the maximum time.
- Reversed the direction of rotation of the ground points.
- Added text IDs next to each ground point.
- Added a straight line from the puck's starting point to the other side of the disk's border, moving at the same rate as the ground points.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
# Parameters
R = 5 # Radius of the disk
v0 = 1 # Initial radial velocity of the puck
omega = 0.2 # Angular velocity of the rotating disk
t_max = 2 * (R / v0) # Doubled the maximum time
num_points = 10
# Initialize figure and axis
fig, ax = plt.subplots()
ax.set_xlim(-R-1, R+1)
ax.set_ylim(-R-1, R+1)
# Draw the disk
disk = plt.Circle((0, 0), R, color='lightgray', fill=True)
ax.add_artist(disk)
# Puck as a point
puck, = ax.plot([], [], 'bo')
# Ground reference points on the circumference of the disk
theta_ground = np.linspace(0, 2*np.pi, num_points)
x_ground = R * np.cos(theta_ground)
y_ground = R * np.sin(theta_ground)
ground_points, = ax.plot(x_ground, y_ground, 'ro')
# Text IDs for ground points
texts = [ax.text(x, y, f"{i}", fontsize=12, ha='right') for i, (x, y) in enumerate(zip(x_ground, y_ground))]
# Line from puck's starting point to the other side of the disk's border
line, = ax.plot([], [], 'k-')
# Animation function
def animate(t):
# Puck's radial position
r_puck = -v0 * t + R
# Angle in the rotating frame (disk rotates with omega)
phi_disk = omega * t # Reversed the direction of rotation
# Transform puck's coordinates to the lab frame (non-rotating perspective)
x_puck = r_puck * np.cos(phi_disk)
y_puck = r_puck * np.sin(phi_disk)
# Update puck position
puck.set_data(x_puck, y_puck)
# Rotate ground reference points
rotation_matrix = np.array([
[np.cos(omega * t), np.sin(omega * t)], # Reversed the direction of rotation
[-np.sin(omega * t), np.cos(omega * t)]
])
rotated_points = rotation_matrix @ np.vstack((x_ground, y_ground))
x_rotated, y_rotated = rotated_points
# Update ground points
ground_points.set_data(x_rotated, y_rotated)
# Update text positions
for i, text in enumerate(texts):
text.set_position((x_rotated[i], y_rotated[i]))
# Update line
line_x = [x_puck, -x_puck] # Line from puck to the opposite side
line_y = [y_puck, -y_puck]
line.set_data(line_x, line_y)
return puck, ground_points, line, *texts
# Create animation
anim = FuncAnimation(fig, animate, frames=np.linspace(0, t_max, 600), interval=20, blit=True)
plt.gca().set_aspect('equal', adjustable='box')
plt.title("Puck's Trajectory from Disk's Inertial Frame")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
# Show the animation
plt.show()
Explanation of Changes:
-
Doubled the Maximum Time: