本征:矩阵到四元数和反数的结果不同 [英] Eigen: matrix to quaternion and back have different result
问题描述
我使用Eigen库将矩阵秘密转换为四元数,但是当我将其中一个矩阵转换为四元数并将其烧回时,它又变成了另一个矩阵,即单位矩阵.我使用的旋转矩阵是从变换矩阵分解而成的.
I use Eigen library to covert matrix to quaternion, but when I turn one of the matrix to quaternion and burn it back, it turn out to be another matrix which is identity matrix. The rotation matrix I use was decomposed from a transform matrix.
Eigen::Matrix3f R3d = R.topLeftCorner<3,3>();
*Rquat = R3d;
R3d = (*Rquat).normalized().toRotationMatrix();
什么可能导致此问题?这是更改为四元数之前的矩阵
What may cause this problem? This is the matrix before change to quaternion
推荐答案
Just checked the implementation of Eigen's matrix to quaternion conversion. It is based on "Quaternion Calculus and Fast Animation", by Ken Shoemake.
正如人们在分析源时所看到的那样,它假设矩阵确实是旋转矩阵(或接近一个旋转矩阵).实际上,所有具有 M.trace()> 0
的对称矩阵都将导致(缩放的)身份四元数.如果您对无效的旋转矩阵还有其他期望,则需要实现自己的转换方法.
And as one can see when analyzing the source, this assumes that the matrix is indeed a rotation matrix (or close to one). In fact all symmetric matrices with M.trace()>0
will result in a (scaled) identity quaternion. If you expect anything else for invalid rotation matrices, you need to implement your own conversion method.
这篇关于本征:矩阵到四元数和反数的结果不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!