我的numpy(python)旋转矩阵不起作用

2024-05-14 17:54:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我做了一个程序来显示不同变换下的矩阵,除了我的旋转矩阵,所有的矩阵都可以工作。我试着摆弄它,但似乎什么也没用

y = input("how many degrees do you want to rotate the shape around the origin?:    ")
j = array([(cos(int(y)), -sin(int(y))), (sin(int(y)), cos(int(y)))])
print(j.dot(w))
input("enter to exit")

Tags: theto程序youinput矩阵sincos
2条回答

正如^{}^{}的python文档所指出的,参数应该在弧度中,而不是中。

可以使用^{}函数将度数转换为弧度。

矩阵定义不正确。试试看

rotMatrix = array([[cos(angle), -sin(angle)], 
                   [sin(angle),  cos(angle)]])

如果你定义了一个向量,比如

vector = array([1, 0])

然后,可以使用矩阵乘法方法“dot”围绕原点旋转该向量:

vector = rotMatrix.dot(vector)

矢量应该围绕原点旋转angle度(辐射角,如前所述)。

相关问题 更多 >

    热门问题