我正在编写python3.5.2上的rotate matrix(1x3)代码。在
为了旋转矩阵,我做了一个函数
def rotate_rpy(posvec: Vector, rotvec: Vector) -> Vector :
return np.dot(np.dot(np.dot (posvec, rotate_rpy(rotvec[0]) ), rotate_pitch(rotvec[1]) ), rotate_yaw(rotvec[2]))
newpose = rotate_rpy(mypose, rotateang)#enbug
它得到了这样一个错误
^{pr2}$也许是个愚蠢的问题,但我不明白是什么问题。在
互联网上的大多数问题都是关于实例化的,但它只是一个函数。不是阶级。不管怎样,我只是试着改变论点:
newpose = rotate_rpy(mypose, mypose, rotateang)#enbug
那么
TypeError: rotate_rpy() takes 2 positional arguments but 3 were given
以及
newpose = rotate_rpy(mypose)#enbug
那么
TypeError: rotate_rpy() missing 1 required positional argument: 'rotvec'
我相信这很傻但是
newpose = rotate_rpy()#enbug
那么
TypeError: rotate_rpy() missing 2 required positional arguments: 'posvec' and 'rotvec'
我很困惑
3 arg-arg太多
2个arg-1个arg错误
1个参数-缺少1个参数
0 arg-缺少2个arg
这不是对应的。我不知道。请帮帮我。。。在
完整代码如下:
#coding:utf-8
import numpy as np
def rotate_roll (th):
_rot_vec_roll = {
{ 1., 0. , 0.},
{ 0., np.cos(th), np.sin(th)},
{ 0., - np.sin(th), np.cos(th)}
}
return _rot_vec_roll
def rotate_pitch (th):
_rot_vec_pitch = {
{ np.cos(th),0. , np.sin(th)},
{ 0., 1., 0.},
{- np.sin(th),1., np.cos(th)}
}
return _rot_vec_pitch
def rotate_yaw (th):
_rot_vec_yaw = {
{ np.cos(th), np.sin(th), 0.},
{ - np.sin(th), np.cos(th), 0.},
{ 0., 0., 1.}
}
return _rot_vec_yaw
# R2 = A * R1
# A = roll_vec * pitch_vec * yaw_vec
Vector = np.ndarray(shape=(1,3), dtype=np.float)
def rotate_rpy(posvec: Vector, rotvec: Vector) -> Vector :
return np.dot(np.dot(np.dot (posvec, rotate_rpy(rotvec[0]) ), rotate_pitch(rotvec[1]) ), rotate_yaw(rotvec[2]))
mypose = np.ndarray(shape=(1,3), dtype=np.float)
mypose = np.array([3.0,1.0,1.0], dtype=float)
print(mypose)
base = np.pi / 6.0
rotateang = np.ndarray(shape=(1,3), dtype=np.float)
rotateang = np.array([base, base/2.0, base], dtype=float)
print(rotateang)
newpose = np.ndarray(shape=(1,3), dtype=np.float)
newpose = rotate_rpy(mypose, rotateang)#enbug
print(newpose);
完整错误如下:
[ 3. 1. 1.]
[ 0.52359878 0.26179939 0.52359878]
Traceback (most recent call last):
File "rotation_matrix.py", line 50, in <module>
newpose = rotate_rpy(mypose, rotateang)#enbug
File "rotation_matrix.py", line 35, in rotate_rpy
return np.dot(np.dot(np.dot (posvec, rotate_rpy(rotvec[0]) ), rotate_pitch(rotvec[1]) ), rotate_yaw(rotvec[2]))
TypeError: rotate_rpy() missing 1 required positional argument: 'rotvec'
函数
rotate_rpy
被定义为无限递归地调用自己(这本身就是一个问题):它也不一致地调用自己,只有一个参数。Python解释器无法捕捉到第一个错误,幸运的是报告了第二个错误。在
相关问题 更多 >
编程相关推荐