Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 使用旋转矩阵偏移欧拉角_Python 2.7_Quaternions_Rotational Matrices_Euler Angles_Vizard - Fatal编程技术网

Python 2.7 使用旋转矩阵偏移欧拉角

Python 2.7 使用旋转矩阵偏移欧拉角,python-2.7,quaternions,rotational-matrices,euler-angles,vizard,Python 2.7,Quaternions,Rotational Matrices,Euler Angles,Vizard,我正在寻找将偏移应用于一组Euler旋转的正确方法。我想要一个变换,给定一组特定的欧拉角(x1,y1,z1),如果我变换它们,我会得到一个(0,0,0)的欧拉序列。所有其他的欧拉序列(xi,yi,zi)转换后的行为将类似于(x1,y1,z1)为(0,0,0) 背景: 我使用Oculus DK2 HMD显示虚拟环境(Vizard 5,Python 2.7.5),同时使用Vicon运动捕捉系统(Nexus 2)更新位置和方向。我可以从维康系统获得头盔显示器的欧拉角(来自标记器组,而不是DK2陀螺仪)

我正在寻找将偏移应用于一组Euler旋转的正确方法。我想要一个变换,给定一组特定的欧拉角(x1,y1,z1),如果我变换它们,我会得到一个(0,0,0)的欧拉序列。所有其他的欧拉序列(xi,yi,zi)转换后的行为将类似于(x1,y1,z1)为(0,0,0)

背景:

我使用Oculus DK2 HMD显示虚拟环境(Vizard 5,Python 2.7.5),同时使用Vicon运动捕捉系统(Nexus 2)更新位置和方向。我可以从维康系统获得头盔显示器的欧拉角(来自标记器组,而不是DK2陀螺仪),但当面对我所需的(0,0,0)方向时,头盔显示器具有非零旋转序列

问题:

我很难思考我能找到什么样的变换(旋转矩阵?)可以取一个序列,比如(-105,110,-30),并使它成为(0,0,0),而不是一个无用的零矩阵。如果旋转矩阵全为零,则任何序列都将转换为(0,0,0))。我想到的公式是(请忽略语法):

[0,0,0]=(3x3)R*(3x1)[-105110,-30]R是什么?R不能是3x3零矩阵

尝试:

我愚蠢地试图简单地减去欧拉角,如下所示:

import viz
viz.go()
navigationNode = viz.addGroup() #create node
viewLink = viz.link(navigationNode, viz.MainView) #link it to the main view

#I am not showing how I get variables HMDX HMDY HMDZ but it's not important for this question
navigationNode.setEuler(HMDRZ-90,HMDRX+180,-1*(HMDRY)+30) #update the view orientation
唉,


我确信这是可能的,事实上我在过去做过类似的事情,我必须在校准位置将标记簇转换为刚体的框架。但我就是无法回避这种情况下的琐碎解决方案(零矩阵)。如果碰巧有人会用四元数来解释这一点,我也可以用它们。

正确的方法是在所需点确定hmd方向和所需视图方向之间的转换。我把这个时间称为零,虽然时间和它没有什么关系,但实际上它是“家”的方向。一旦知道变换,就可以使用来自hmd的数据来确定视图方向,因为hmd和视图的坐标系可以被视为安装在同一刚体上(这意味着它们的相对变换不会随时间变化)

以下是数学:

下面是我如何编码它(它工作!):


我可能在这里遗漏了一些非常基本的东西,但假设您有
[-105110,-30]
,并希望使用矩阵
R
将其转换为
[0,0,0]
。那么,您是否可以在
R
的每一行中使用例如
[0,1110/30]
!?如果是这样,那么这个问题显然有很多解决方案;如果不是的话,我真的不明白你的问题。好的,你能再详细解释一下你到底在找什么吗?我只举了一个武断的例子;您还可以选择
[-1,1,43/6]
,这显然不会为
(-105+45110,-30)
返回
(0,0,0)
。因此,如果您能更详细地解释
R
的期望属性,那就太好了!如果您能够详细定义
R
的属性,您也可以尝试一下。@Cleb很抱歉造成混淆,我认为您描述的是通过将向量与旋转矩阵相乘来变换向量。有许多矩阵R可以将向量变成零。但是,对于Euler角度,不能简单地将Euler角度乘以旋转矩阵。那没有道理。而是与另一个旋转矩阵相乘,并使用反向运动学获得新的Euler角度。我希望我说的有道理。谢谢你的回答,谢谢你的解释;我可以学到一些东西:)
import numpy as np
import math

#setup the desired calibration transformation (hmd orientation that will result in looking straight ahead

#Euler angles for the hmd at desired "zero" orientation
a0 = -177.9*math.pi/180
b0 = 31.2*math.pi/180
g0 = 90.4*math.pi/180

#make the matrices
Ra0 = np.matrix([[1,0,0],[0, float(math.cos(a0)),float(-1*math.sin(a0))],[0,float(math.sin(a0)),float(math.cos(a0))]],dtype=np.float)
Rb0 = np.matrix([[math.cos(b0),0,math.sin(b0)],[0,1,0],[-1*math.sin(b0),0,math.cos(b0)]],dtype=np.float)
Rg0 = np.matrix([[math.cos(g0),-1*math.sin(g0),0],[math.sin(g0),math.cos(g0),0],[0,0,1]],dtype=np.float)

#the hmd rotation matrix in the "zero" orientation
global RhmdU0 
RhmdU0 = Ra0*Rb0*Rg0
#the view orientation when the hmd is in the "zero" orientation (basically a zero degree turn about the Z axis)
global RdU0
RdU0 = np.matrix([[1,0,0],[0,1,0],[0,0,1]],dtype=np.float)

#this can be called in a loop, inputs are Euler angles of the hmd
def InverseK(at,bt,gt):
    global RdU0
    global RhmdU0

    #given 3 Euler sequence of the hmd in universal space, determine the viewpoint
    Rat = np.matrix([[1,0,0],[0, float(math.cos(at)), float(-1*math.sin(at))],[0,float(math.sin(at)),float(math.cos(at))]],dtype=np.float)
    Rbt = np.matrix([[math.cos(bt),0,math.sin(bt)],[0,1,0],[-1*math.sin(bt),0,math.cos(bt)]],dtype=np.float)
    Rgt = np.matrix([[math.cos(gt),-1*math.sin(gt),0],[math.sin(gt),math.cos(gt),0],[0,0,1]],dtype=np.float)

    RhmdUt = Rat*Rbt*Rgt

    RdUt = RhmdUt*RhmdU0.transpose()*RdU0

    #do inverse K to get euler sequence out:
    beta = math.atan2(RdUt[0,2],math.sqrt(RdUt[1,2]**2+RdUt[2,2]**2))
    alpha = math.atan2(-1*RdUt[1,2]/math.cos(beta),RdUt[2,2]/math.cos(beta))
    gamma = math.atan2(-1*RdUt[0,1]/math.cos(beta),RdUt[0,0]/math.cos(beta))

    return(alpha,beta,gamma)