so I’m quit new to simulations in python and I tried to simulate the cart and pendulum problem as shown here
I don’t know why but the animation is distorting the length of the pendulum rope.
It happened also with regular pendulum simulations so i finally decided to ask.
I checked the length of the rope and it doesn’t seem to change so i think the problem is with the animation proportions.
Relevant code block:
def animate(i):
ln.set_data([0, x1_vals[i], x2_vals[i]], [0, 0, y2_vals[i]])
fig, ax = plt.subplots(1, 1, figsize = (8, 8))
ax.get_xaxis().set_ticks([])
ax.get_yaxis().set_ticks([])
ln, = ax.plot([], [], 'r--', lw = 3, marker = 'o', markersize = 12)
ax.set_xlim(min(min(x1_vals), min(x2_vals)),max(max(x1_vals), max(x2_vals)))
ax.set_ylim(min(0, min(y2_vals)),max(0, max(y2_vals)))
ani = animation.FuncAnimation(fig, animate, frames = 1001, interval = 50)
ani.save('CartAndPendulum.gif', writer='pillow', fps = 25)
-
shorter rope
-
longer rope
-
Constant rope length demonstrated:
aviram ohayon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.