import sympy as sy
import matplotlib.pyplot as plt
fi,b=sy.symbols('fi,b')
p=2*b*sy.sqrt(sy.Abs(sy.cos(2*fi)))
xp=p*sy.cos(fi)
yp=p*sy.sin(fi)
xp_v=xp.subs({b:300})
yp_v=yp.subs({b:300})
sy.plot_parametric(xp_v,yp_v,(fi,0,2*sy.pi))
import sympy as sy
import numpy as np
import matplotlib.pyplot as plt
fi,b=sy.symbols('fi,b')
p=b*sy.sin(3*fi)
xp=p*sy.cos(fi)
yp=p*sy.sin(fi)
xp_v=xp.subs({b:300})
yp_v=yp.subs({b:300})
# sy.plot_parametric(xp_v,yp_v,(fi,0,2*sy.pi))
tt=np.linspace(0,2*np.pi,num=100)
px = sy.lambdify(fi, xp_v, modules='numpy')
py= sy.lambdify(fi, yp_v, modules='numpy')
fi_v=10*np.pi/180
a=300
Ex=0
Ey=a+2*a-4*a*np.sin(fi_v)*np.sin(fi_v)
Dx=Ex+4*a*np.sin(fi_v)*np.cos(fi_v)
Dy=Ey+4*a*np.sin(fi_v)*np.sin(fi_v)
Cx=Dx
Cy=a
O1x=0
O1y=a
Bx=Dx
By=-a
fig = plt.figure(figsize=(5, 5))
plt.rcParams['xtick.direction'] = 'in' # 将x周的刻度线方向设置向内
plt.rcParams['ytick.direction'] = 'in' # 将y轴的刻度方向设置向内
clist = ['blue', 'red', 'green', 'black', 'darkgreen', 'lime', 'gold', 'purple', 'green', 'cyan', 'salmon', 'grey',
'mediumvioletred', 'darkkhaki', 'gray', 'darkcyan', 'violet', 'powderblue']
# ==========================================
plt.plot([0,px(fi_v)],[0,py(fi_v)], c=clist[0])
plt.plot([0,Ex],[0,Ey], c=clist[1])
plt.plot([Dx,Ex],[Dy,Ey], c=clist[2])
plt.plot([Dx,Bx],[Dy,By], c=clist[3])
plt.plot([Ex,Bx],[Ey,By], c=clist[4])
plt.plot(px(tt),py(tt), c=clist[5])
plt.plot([-600,600],[a,a], c=clist[6])
plt.show()