我已经在互联网上搜索并阅读了Eigen教程,以及关于转换,旋转的所有内容,但我无法想象如何将旋转应用于2向量。通常是矩阵矢量积。 我正在使用Visual Studio 2010.Windows 7.这是我的代码
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <Eigen/Dense>
#include <Eigen/Geometry>
using namespace std;
using Eigen::VectorXd;
using Eigen::VectorXf;
using Eigen::Vector2d;
using Eigen::Vector2f;
using Eigen::Rotation2Df;
int main(){
Vector2f v;
v << 100.0f,200.0f;
cout << "\nthe initial vector is v = \n" << endl << v << endl << endl;
float theta = M_PI/4;
//Eigen::AffineCompact2d t;
Rotation2Df t(theta);
t.toRotationMatrix();
printf ("\nUsing an Affine2f\n");
cout <<"\nthe rotation Matrix is \n"<< t.matrix() << std::endl;
Vector2f rotatedVect = t*v.transpose();
cout <<"the rotated vector is \n"<< rotatedVect << std::endl;
std::cin.get();
}
问题出在这一行:
Vector2f rotatedVect = t*v.transpose();
这就像乘法运算符需要使用它一样困惑。如果连接或矩阵向量乘法。我喜欢这个库,但此时我正在认真地重新考虑在我的项目中使用它。这是Visual Studio 2010在运行代码时生成的错误。我将不胜感激任何帮助!
1>------ Rebuild All started: Project: GettingStarted, Configuration: Debug x64 ------
1>Build started 5/25/2016 12:52:03 PM.
1>_PrepareForClean:
1> Deleting file "x64\Debug\GettingStarted.lastbuildstate".
1>InitializeBuildStatus:
1> Creating "x64\Debug\GettingStarted.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> firstprog.cpp
1>firstprog.cpp(18): warning C4305: 'initializing' : truncation from 'double' to 'float'
1>firstprog.cpp(24): error C2666: 'Eigen::Rotation2D<_Scalar>::operator *' : 2 overloads have similar conversions
1> with
1> [
1> _Scalar=float
1> ]
1> c:\users\maider\eigen\src/Geometry/Rotation2D.h(85): could be 'Eigen::Matrix<_Scalar,_Rows,_Cols> Eigen::Rotation2D<_Scalar>::operator *(const Eigen::Matrix<_Scalar,_Rows,_Cols> &) const'
1> with
1> [
1> _Scalar=float,
1> _Rows=2,
1> _Cols=1
1> ]
1> c:\users\maider\eigen\src/Geometry/RotationBase.h(71): or 'Eigen::Matrix<_Scalar,_Rows,_Cols> Eigen::RotationBase<Derived,_Dim>::operator *<Eigen::Transpose<MatrixType>>(const Eigen::EigenBase<Eigen::Transpose<MatrixType>> &) const'
1> with
1> [
1> _Scalar=float,
1> _Rows=2,
1> _Cols=1,
1> Derived=Eigen::Rotation2D<float>,
1> _Dim=2,
1> MatrixType=Eigen::Matrix<float,2,1>
1> ]
1> while trying to match the argument list '(Eigen::Rotation2Df, Eigen::Transpose<MatrixType>)'
1> with
1> [
1> MatrixType=Eigen::Matrix<float,2,1>
1> ]
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.02
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
答案 0 :(得分:0)
首先检查Eigen的版本,看起来版本3.2.3及更低版本的运算符*的重载存在问题。请参阅https://forum.kde.org/viewtopic.php?f=74&t=124235&p=326983&hilit=Rotation2D#p326983 但是在我下载了最新版本并使用
重新运行我的代码之后Vector2f rotatedVect = t.toRotationMatrix()*v;
有效!