python利用matplotlib库根据中心坐标与方位角绘制矩形
import matplotlib.pyplot as plt
import math
def convert_center_to_leftdown(x_cord, y_cord, angle, width, height):
xp = x_cord-(math.sqrt(width**2+height**2)/2)*math.cos(math.atan2(height, width)+angle/180*math.pi)
yp = y_cord-(math.sqrt(width**2+height**2)/2)*math.sin(math.atan2(height, width)+angle/180*math.pi)
return xp, yp
fig1 = plt.figure()
axes1 = fig1.add_subplot(1, 1, 1)
x = 0.5
y = 0.5
phi = -30
w = 0.2
h = 0.1
xp, yp = convert_center_to_leftdown(x, y, phi, w, h)
square = plt.Rectangle(xy=(xp, yp), width=w, height=h, alpha=0.8, angle=phi)
axes1.add_patch(square)
axes1.axis('equal')
axes1.grid()
plt.show()