旋转矩阵

时间:2019-08-06 02:13:48

标签: python matplotlib

我正在尝试将给定的图形旋转90度。

fig = plt.figure()
points = [[0.3036, 0.1960], [0.6168, 0.2977], [0.7128, 0.4169], [0.7120, 0.1960],[0.9377,0.2620],\
          [0.7120,0.5680],[0.3989,0.6697],[0.3028,0.7889],[0.3036,0.5680],[0.5293,0.5020]]

bird = matplotlib.patches.Polygon(points, facecolor='blue')

fig, ax = plt.subplots()
ax.set_aspect("equal")
ax.add_patch(bird)

ax.set_xlim(0.2,1)
ax.set_ylim(0.2,0.9)
plt.show() 

1 个答案:

答案 0 :(得分:4)

要旋转矩阵,您基本上将坐标乘以一个旋转矩阵,该旋转矩阵由

给出
[[cos(theta), -sin(theta)], [sin(theta), cos(theta)]]

theta是旋转角度(因此,在您的情况下为[[0,-1],[1,0]])。

所以您只需要像这样计算点积:

points = np.array(points)
rotation_matrix = np.array([[0, -1], [1, 0]])
new_points = points.dot(rotation_matrix)

,然后可以绘制新的坐标集。这是结果(在将(0,1)添加到坐标之后,使得小鸟在帧中... enter image description here