簡體   English   中英

旋轉矩陣

[英]Rotate a matrix

我正在嘗試將給定的圖形旋轉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() 

要旋轉矩陣,您基本上將坐標乘以一個旋轉矩陣,即

[[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)添加到坐標之后,使得小鳥在幀中... 在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM