Python 如何顺时针或逆时针旋转2D矢量?
我试图根据指令数据库旋转一个Y轴方向的幺正向量a 向量被描述为x1,x2,y1,y2Python 如何顺时针或逆时针旋转2D矢量?,python,numpy,math,vector,Python,Numpy,Math,Vector,我试图根据指令数据库旋转一个Y轴方向的幺正向量a 向量被描述为x1,x2,y1,y2 A = np.array([ 0 ,0 ] , [ 0 , 1 ] ) Database = ['left', 'right', 'right', ... ] 例如,如果我们顺时针旋转4次,我们应该得到: #First spin [(0,1),(0,0)] #Second spin [(0,0),(0,-1)] #third spin [(0,-1),(0,0)]] #fourth spin [(0,0),(
A = np.array([ 0 ,0 ] , [ 0 , 1 ] )
Database = ['left', 'right', 'right', ... ]
例如,如果我们顺时针旋转4次,我们应该得到:
#First spin
[(0,1),(0,0)]
#Second spin
[(0,0),(0,-1)]
#third spin
[(0,-1),(0,0)]]
#fourth spin
[(0,0),(0,1)]
可以通过将向量乘以一个值来旋转向量。给定示例将初始向量逆时针旋转30度,就像笛卡尔坐标系中的正角度一样:
A = np.array([ 0 , 1])
theta = np.radians(30)
c, s = np.cos(theta), np.sin(theta)
R = np.array(((c,-s), (s, c)))
A = np.dot(R, A)
我编辑了数组,所以现在它不再是向量了。0,0都不是单位向量。如果你逆时针定向一个向量x,y=0,1,你将得到0,1->-1,0->0,-1->1,0。