2 回答

TA貢獻2065條經驗 獲得超14個贊
如果您總是只想旋轉 90 度并且始終保持相同的方向(因此rot90
沒有任何其他參數(shù)),您可以使用以下公式:
idx2 = np.array([[n.shape[0]-1-x[1], x[0]] for x in idx])
假設idx
是您的索引數(shù)組 (2, 3866) 和n
您想要索引的網格 (522, 476)。它只是使用單次旋轉對元素的作用的知識,即將第一維切換到第二維,并使第二維從末尾開始計算為第一維。

TA貢獻1845條經驗 獲得超8個贊
您可以定義一個旋轉函數(shù):
def rotate(origin, point, angle):
"""
Rotate a point counterclockwise by a given angle around a given origin.
The angle should be given in radians.
"""
ox, oy = origin
px, py = point
qx = ox + math.cos(angle) * (px - ox) - math.sin(angle) * (py - oy)
qy = oy + math.sin(angle) * (px - ox) + math.cos(angle) * (py - oy)
return qx, qy
然后將此函數(shù)應用于軌跡的所有 (X,Y) 點。
origin = tuple(0, 0)
newTrajectory = []
for i in range(0:len(trajectory[0])):
p = tuple(trajectory[i][0], trajectory[i][1])
newP = rotate(origin, p, math.pi/2)
row = [newP[0], newP[1]]
newTrajectory.append(row)
最好的事物
添加回答
舉報