2012-04-13 28 views
4

我正在制作一个程序来显示各种变换下的矩阵,除了我的旋转矩阵外,它们都可以工作。香港专业教育学院试图与它摆弄,但似乎没有任何工作我的旋转矩阵为numpy(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") 

回答

10

至于cos Python文档和sin点出,参数应该是弧度,不

您可以使用math.radians函数将度数转换为弧度。

+0

谢谢你的工作 – goomba 2012-04-13 02:09:50

2

您的矩阵未正确定义。尝试

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

如果你定义一个矢量,说

vector = array([1, 0]) 

使用矩阵乘法方法 '点' 然后你可以旋转这个向量围绕原点

vector = rotMatrix.dot(vector) 

这种载体应围绕原点旋转angle度(辐射角度,如前所述)。