我正在制作一个程序来在各种变换下显示矩阵,除了我的旋转矩阵之外,它们都可以工作。香港专业教育学院试图摆弄它,但似乎没有任何工作
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")
答案 0 :(得分:10)
正如cos
和sin
的python文档指出的那样,参数应该是 radians ,而不是度。
您可以使用math.radians
功能将度数转换为弧度。
答案 1 :(得分:2)
您的矩阵未正确定义。尝试
rotMatrix = array([[cos(angle), -sin(angle)],
[sin(angle), cos(angle)]])
如果您定义了一个矢量,请说
vector = array([1, 0])
然后你可以使用矩阵乘法'dot'旋转这个矢量在原点附近:
vector = rotMatrix.dot(vector)
矢量应该绕原点旋转angle
度(辐射角,如前所述)。