gpt4 book ai didi

c++ - Eigen:将 Matrix3d 旋转转换为四元数

转载 作者:IT老高 更新时间:2023-10-28 22:35:43 25 4
gpt4 key购买 nike

我正在尝试转换 Matrix3d旋转到 Quaternion<double> ,但到目前为止我只得到了奇怪的编译器错误。我使用的代码是:

Quaternion<double> getQuaternionFromRotationMatrix(const Matrix3d& mat)
{
AngleAxisd aa;
aa = mat;
Quaternion<double> q = aa;// conversion error

return q;
}

以及编译器错误:

path/src/Utils.cpp: In function ‘Eigen::Quaternion<double> Utils::getQuaternionFromRotationMatrix(const Matrix3d&)’:
path/src/Utils.cpp:55:26: error: conversion from ‘Eigen::AngleAxisd {aka Eigen::AngleAxis<double>}’ to non-scalar type ‘Eigen::Quaternion<double>’ requested
In file included from /usr/local/include/eigen3/Eigen/Core:283:0,
from /usr/local/include/eigen3/Eigen/Dense:1,
from path/include/Utils.h:4,
from path/src/Utils.cpp:1:
/usr/local/include/eigen3/Eigen/src/Core/Assign.h: In member function ‘Derived& Eigen::DenseBase<Derived>::lazyAssign(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<double, 3, 1>, Derived = Eigen::Block<Eigen::Matrix<double, 4, 4>, 4, -0x00000000000000001, true, true>]’:
/usr/local/include/eigen3/Eigen/src/Core/Assign.h:534:123: instantiated from ‘static Derived& Eigen::internal::assign_selector<Derived, OtherDerived, false, false>::run(Derived&, const OtherDerived&) [with Derived = Eigen::Block<Eigen::Matrix<double, 4, 4>, 4, -0x00000000000000001, true, true>, OtherDerived = Eigen::Matrix<double, 3, 1>]’
/usr/local/include/eigen3/Eigen/src/Core/Assign.h:574:89: instantiated from ‘Derived& Eigen::MatrixBase<Derived>::operator=(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<double, 3, 1>, Derived = Eigen::Block<Eigen::Matrix<double, 4, 4>, 4, -0x00000000000000001, true, true>]’
path/src/Utils.cpp:34:20: instantiated from here
/usr/local/include/eigen3/Eigen/src/Core/Assign.h:504:3: error: static assertion failed: "YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES"

有人知道如何在两种表示之间进行转换吗?

最佳答案

AngleAxisMatrix 的构造函数是 explicit 意味着您必须编写如下转换:

Matrix3f mat;
Quaternionf q(mat);

Quaternionf q;
q = mat;

AngleAxis 也一样。

关于c++ - Eigen:将 Matrix3d 旋转转换为四元数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21761909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com