移动双点输入连杆夹持机构

移动双点输入连杆夹持机构_第1张图片

import sympy as sy
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
a,b,c,d,e,L,F,S=sy.symbols("a,b,c,d,e,L,F,S")
k1=c*(d-a)
k2=-2*S*c
k3=S**2+c**2+(d-a)**2/4-b**2
pu=2*sy.atan((-k1+sy.sqrt(k1**2+k2**2-k3**2))/(k3-k2))
fi=sy.atan((0.5*d-0.5*a+c*sy.sin(pu))/(S-c*sy.cos(pu)))
F23=F*(L*sy.cos(pu)+e*sy.sin(pu))/(c*sy.sin(fi+pu))
F1=2*F23*sy.cos(fi)
Ax=-S
Bx=-S+b*sy.cos(fi)
By=a/2+b*sy.sin(fi)
B1x=-Bx
B1y=d/2-c*sy.sin(pu)
acx=sy.lambdify(S,Ax.subs({a:30,b:80,c:50,d:120,e:20,L:150,F:1200}),modules='numpy')
bx=sy.lambdify(S,Bx.subs({a:30,b:80,c:50,d:120,e:20,L:150,F:1200}),modules='numpy')
by=sy.lambdify(S,By.subs({a:30,b:80,c:50,d:120,e:20,L:150,F:1200}),modules='numpy')
b1x=sy.lambdify(S,B1x.subs({a:30,b:80,c:50,d:120,e:20,L:150,F:1200}),modules='numpy')
b1y=sy.lambdify(S,B1y.subs({a:30,b:80,c:50,d:120,e:20,L:150,F:1200}),modules='numpy')


fig,ax = plt.subplots()
plt.rcParams['xtick.direction'] = 'in'  # 将x周的刻度线方向设置向内
plt.rcParams['ytick.direction'] = 'in'  # 将y轴的刻度方向设置向内
plt.rcParams['axes.unicode_minus']=False
# plt.rcParams['font.family'] = ["Times New Roman"]  # 字体设置为Times NewRoman
plt.rcParams['font.sans-serif'] = ['SimHei']
clist = ['blue', 'red', 'green', 'black', 'darkgreen', 'lime', 'gold', 'purple', 'green', 'cyan', 'salmon', 'grey',
         'mediumvioletred', 'darkkhaki', 'gray', 'darkcyan', 'violet', 'powderblue']
markerlst = ['o', '*', 'x', '>', '<', '^', 'D', 'd', '1', '2', '3', '4', 'o', '*', 'x', '>', '<', '^', 'D', 'd',
             '1', '2', '3', '4', 'o', '*', 'x', '>', '<', '^', 'D', 'd', '1', '2', '3', '4']
linestylelst = ['-', '--', '-.', ':', '-', '--', '-.', ':', '-', '--', '-.', ':', '-', '--', '-.', ':', '-', '--',
                '-.', ':', '-', '--', '-.', ':']
def draw_frame(i):
    s=50+i
    xa=acx(s)
    ya=15
    xb=bx(s)
    yb=by(s)
    xb1 = b1x(s)
    yb1 = b1y(s)
    xc=0
    yc=60
    ax.clear()
    ax.plot([xa, 0], [0, 0], c=clist[0])
    ax.plot([xa,xb],[ya,yb],c=clist[1])
    ax.plot([xb1, xb], [yb1, yb], c=clist[2])
    ax.plot([xc, xc], [-yc, yc], c=clist[3])
    ax.plot([xa, xa], [-ya, ya], c=clist[4])
    ax.plot([xa, xb], [-ya, -yb], c=clist[5])
    ax.plot([xb1, xb], [-yb1, -yb], c=clist[6])
    ax.axis('equal')
    ax.set_xlim(xmin=-150,xmax=150)
    ax.set_ylim(ymin=-150, ymax=150)
    plt.tight_layout()


anim=FuncAnimation(fig,draw_frame,frames=50,interval=50)
anim.save("d3.gif",writer='pillow')

移动双点输入连杆夹持机构_第2张图片

你可能感兴趣的:(python,numpy,matplotlib)