import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.animation import FuncAnimation
# ParametersR = 2.0 # Red bead orbit radiusd = 0.1 # Blue bead distance from red beadr_g = 0.5 # Green bead orbit radius around red bead
omega_main = 1.0 # Main rotation frequencyomega_orbit = 2.0 # Green bead's own rotation frequency
dt = 0.05
# Lists to store trajectory pointstrail_red_x, trail_red_y = [], []trail_blue_x, trail_blue_y = [], []trail_green_x, trail_green_y = [], []
# Figurefig, ax = plt.subplots()ax.set_aspect('equal')ax.set_xlim(-3, 3)ax.set_ylim(-3, 3)
# Orbital reference circletheta = np.linspace(0, 2*np.pi, 300)ax.plot(R*np.cos(theta), R*np.sin(theta), 'k--')
# Beadsred_bead, = ax.plot([], [], 'ro', markersize=12)blue_bead, = ax.plot([], [], 'bo', markersize=8)green_bead, = ax.plot([], [], 'go', markersize=10)
# Connecting rodsrod_rb, = ax.plot([], [], 'gray', linewidth=2)rod_rg, = ax.plot([], [], 'gray', linewidth=2)
# Trails (grey lines)trail_red_line, = ax.plot([], [], color='gray', linewidth=0.5)trail_blue_line, = ax.plot([], [], color='gray', linewidth=1)trail_green_line, = ax.plot([], [], color='green', linewidth=3)
def update(frame): t = frame * dt
# --- Main bead rotation --- angle = omega_main * t
# Red bead position x_r = R * np.cos(angle) y_r = R * np.sin(angle)
# Blue bead (rigid link) x_b = x_r + d * np.cos(angle) y_b = y_r + d * np.sin(angle)
# Green bead (rotating around red) phi = omega_orbit * t x_g = x_r + r_g * np.cos(phi) y_g = y_r + r_g * np.sin(phi)
# Update positions red_bead.set_data([x_r], [y_r]) blue_bead.set_data([x_b], [y_b]) green_bead.set_data([x_g], [y_g]) # Update rods rod_rb.set_data([x_r, x_b], [y_r, y_b]) rod_rg.set_data([x_r, x_g], [y_r, y_g])
# Add trail points trail_red_x.append(x_r); trail_red_y.append(y_r) trail_blue_x.append(x_b); trail_blue_y.append(y_b) trail_green_x.append(x_g); trail_green_y.append(y_g)
# Update trail lines trail_red_line.set_data(trail_red_x, trail_red_y) trail_blue_line.set_data(trail_blue_x, trail_blue_y) trail_green_line.set_data(trail_green_x, trail_green_y)
return red_bead, blue_bead, green_bead, rod_rb, rod_rg, trail_red_line, trail_blue_line, trail_green_line
ani = FuncAnimation(fig, update, frames=1000, interval=30, blit=True)
plt.title("Three Beads with Motion Trails")plt.show()