import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# Parametry mechanizmu
r = 1.0 # długość korby
l = 3.0 # długość łącznika
theta = np.linspace(0, 2 * np.pi, 100) # kąt obrotu
# Funkcja do obliczania pozycji suwaków
def calculate_positions(theta, r, l):
x1 = r * np.cos(theta)
y1 = r * np.sin(theta)
x2 = r * np.cos(theta + np.pi / 2)
y2 = r * np.sin(theta + np.pi / 2)
x3 = r * np.cos(theta + np.pi)
y3 = r * np.sin(theta + np.pi)
x4 = r * np.cos(theta + 3 * np.pi / 2)
y4 = r * np.sin(theta + 3 * np.pi / 2)
return x1, y1, x2, y2, x3, y3, x4, y4
# Tworzenie wykresu
fig, ax = plt.subplots()
ax.set_xlim(-l, l)
ax.set_ylim(-l, l)
# Linie reprezentujące korby i suwaki w różnych kolorach
crank1, = ax.plot([], [], 'o-', lw=2, color='red')
crank2, = ax.plot([], [], 'o-', lw=2, color='green')
crank3, = ax.plot([], [], 'o-', lw=2, color='blue')
crank4, = ax.plot([], [], 'o-', lw=2, color='purple')
link1, = ax.plot([], [], 'o-', lw=2, color='orange')
link2, = ax.plot([], [], 'o-', lw=2, color='cyan')
link3, = ax.plot([], [], 'o-', lw=2, color='magenta')
link4, = ax.plot([], [], 'o-', lw=2, color='yellow')
# Inicjalizacja animacji
def init():
crank1.set_data([], [])
crank2.set_data([], [])
crank3.set_data([], [])
crank4.set_data([], [])
link1.set_data([], [])
link2.set_data([], [])
link3.set_data([], [])
link4.set_data([], [])
return crank1, crank2, crank3, crank4, link1, link2, link3, link4
# Aktualizacja animacji
def animate(i):
x1, y1, x2, y2, x3, y3, x4, y4 = calculate_positions(theta[i], r, l)
crank1.set_data([0, x1], [0, y1])
link1.set_data([x1, x1], [y1, y1 + l])
crank2.set_data([0, x2], [0, y2])
link2.set_data([x2, x2 + l], [y2, y2])
crank3.set_data([0, x3], [0, y3])
link3.set_data([x3, x3], [y3, y3 - l])
crank4.set_data([0, x4], [0, y4])
link4.set_data([x4, x4 - l], [y4, y4])
return crank1, crank2, crank3, crank4, link1, link2, link3, link4
# Tworzenie animacji
ani = animation.FuncAnimation(fig, animate, init_func=init, frames=len(theta), interval=50, blit=True)
plt.show()
aW1wb3J0IG51bXB5IGFzIG5wCmltcG9ydCBtYXRwbG90bGliLnB5cGxvdCBhcyBwbHQKaW1wb3J0IG1hdHBsb3RsaWIuYW5pbWF0aW9uIGFzIGFuaW1hdGlvbgoKIyBQYXJhbWV0cnkgbWVjaGFuaXptdQpyID0gMS4wICAjIGTFgnVnb8WbxIcga29yYnkKbCA9IDMuMCAgIyBkxYJ1Z2/Fm8SHIMWCxIVjem5pa2EKdGhldGEgPSBucC5saW5zcGFjZSgwLCAyICogbnAucGksIDEwMCkgICMga8SFdCBvYnJvdHUKCiMgRnVua2NqYSBkbyBvYmxpY3phbmlhIHBvenljamkgc3V3YWvDs3cKZGVmIGNhbGN1bGF0ZV9wb3NpdGlvbnModGhldGEsIHIsIGwpOgogICAgeDEgPSByICogbnAuY29zKHRoZXRhKQogICAgeTEgPSByICogbnAuc2luKHRoZXRhKQogICAgeDIgPSByICogbnAuY29zKHRoZXRhICsgbnAucGkgLyAyKQogICAgeTIgPSByICogbnAuc2luKHRoZXRhICsgbnAucGkgLyAyKQogICAgeDMgPSByICogbnAuY29zKHRoZXRhICsgbnAucGkpCiAgICB5MyA9IHIgKiBucC5zaW4odGhldGEgKyBucC5waSkKICAgIHg0ID0gciAqIG5wLmNvcyh0aGV0YSArIDMgKiBucC5waSAvIDIpCiAgICB5NCA9IHIgKiBucC5zaW4odGhldGEgKyAzICogbnAucGkgLyAyKQogICAgCiAgICByZXR1cm4geDEsIHkxLCB4MiwgeTIsIHgzLCB5MywgeDQsIHk0CgojIFR3b3J6ZW5pZSB3eWtyZXN1CmZpZywgYXggPSBwbHQuc3VicGxvdHMoKQpheC5zZXRfeGxpbSgtbCwgbCkKYXguc2V0X3lsaW0oLWwsIGwpCgojIExpbmllIHJlcHJlemVudHVqxIVjZSBrb3JieSBpIHN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