Eigen 中的 Quaternion

参考网址:
http://eigen.tuxfamily.org/dox-devel/classEigen_1_1Quaternion.html

http://www.cc.gatech.edu/classes/AY2015/cs4496_spring/Eigen.html

Eigen中quaternion的构造函数为
Quaternion (const Scalar &w, const Scalar &x, const Scalar &y, const Scalar &z),注意w在前。然而在内部存储时eigen将四元数的w放在最后
例如通过Eigen::Vector4d q = q_AB.coeffs();访问时,q中的最后一个元素才是w。

Eigen中用四元数表示向量的旋转
Quaternion:

Eigen::Quaterniond q(2, 0, 1, -3);
std::cout << “This quaternion consists of a scalar ” << q.w() << ” and a vector ” << std::endl << q.vec() << std::endl;
q.normalize();
std::cout << “To represent rotation, we need to normalize it such that its length is ” << q.norm() << std::endl;
Eigen::Vector3d v(1, 2, -1);
Eigen::Quaterniond p;
p.w() = 0;
p.vec() = v;
Eigen::Quaterniond rotatedP = q * p * q.inverse();
Eigen::Vector3d rotatedV = rotatedP.vec();
std::cout << “We can now use it to rotate a vector ” << std::endl << v << ” to ” << std::endl << rotatedV << std::endl;

Eigen::Matrix3d R = q.toRotationMatrix(); // convert a quaternion to a 3x3 rotation matrix
std::cout << “Compare with the result using an rotation matrix ” << std::endl << R * v << std::endl;

Eigen::Quaterniond a = Eigen::Quterniond::Identity();
Eigen::Quaterniond b = Eigen::Quterniond::Identity();
Eigen::Quaterniond c; // Adding two quaternion as two 4x1 vectors is not supported by the EIgen API. That is, c = a + b is not allowed. We have to do this in a hard way
c.w() = a.w() + b.w();
c.x() = a.x() + b.x();
c.y() = a.y() + b.y();
c.z() = a.z() + b.z();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值