Code
Code
# Link lengths
L1 = 2.0 # Base
L2 = 1.0 # Input link
L3 = 1.0 # Output link
L4 = 2.0 # Coupler (same as base for parallelogram)
# Base points
A = np.array([0, 0])
D = np.array([L1, 0])
def update_link_positions(theta):
# Input point B
B = A + L2 * np.array([np.cos(theta), np.sin(theta)])
# Find point C using parallelogram constraint (same length and opposite side)
# Vector from B to A
BA = A - B
# Point C is at B + same direction as D to A
C = D + BA
return A, B, C, D
def init():
line.set_data([], [])
return line,
def animate(i):
theta = theta_range[i]
A, B, C, D = update_link_positions(theta)
xdata = [A[0], B[0], C[0], D[0], A[0]]
ydata = [A[1], B[1], C[1], D[1], A[1]]
line.set_data(xdata, ydata)
title.set_text(f"Input Angle: {np.degrees(theta):.1f}°")
return line, title
plt.show()