C++ 应用于2矢量的本征旋转2D

C++ 应用于2矢量的本征旋转2D,c++,visual-studio-2010,rotation,eigen,C++,Visual Studio 2010,Rotation,Eigen,我在互联网上搜索并阅读了Eigen教程,以及所有关于变换、旋转的内容,但我不知道如何将旋转应用于2向量。通常是矩阵向量积。 我正在使用VisualStudio2010。视窗7。这是我的密码 #define _USE_MATH_DEFINES #include <iostream> #include <cmath> #include <Eigen/Dense> #include <Eigen/Geometry> using namespace s

我在互联网上搜索并阅读了Eigen教程,以及所有关于变换、旋转的内容,但我不知道如何将旋转应用于2向量。通常是矩阵向量积。 我正在使用VisualStudio2010。视窗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();
}
这就像是混淆了需要使用哪个乘法运算符。如果是串联或矩阵向量乘法。我喜欢这个库,但现在我正在认真地重新考虑在我的项目中使用它。这是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 ==========
1>----已启动全部重建:项目:GettingStarted,配置:Debug x64------
1> 建造开始于2016年5月25日下午12:52:03。
1> _PrepareForClean:
1> 正在删除文件“x64\Debug\GettingStarted.lastbuildstate”。
1> 初始化BuildStatus:
1> 创建“x64\Debug\GettingStarted.Build”失败,因为指定了“AlwaysCreate”。
1> CLC编译:
1> firstprog.cpp
1> firstprog.cpp(18):警告C4305:“正在初始化”:从“double”截断为“float”
1> firstprog.cpp(24):错误C2666:'Eigen::Rotation2D::operator*':2个重载具有类似的转换
1> 与
1>          [
1> _标量=浮点
1>          ]
1> c:\users\maider\eigen\src/Geometry/Rotation2D.h(85):可以是“eigen::Matrix eigen::Rotation2D::operator*(const eigen::Matrix&)const”
1> 与
1>          [
1> _标量=浮点,
1> _行=2,
1> _Cols=1
1>          ]
1> c:\users\maider\eigen\src/Geometry/RotationBase.h(71):或“eigen::Matrix eigen::RotationBase::operator*(const eigen::EigenBase&)const”
1> 与
1>          [
1> _标量=浮点,
1> _行=2,
1> _Cols=1,
1> 派生=特征::旋转2D,
1> _Dim=2,
1> 矩阵类型=特征::矩阵
1>          ]
1> 尝试匹配参数列表时“(Eigen::Rotation2Df,Eigen::Transpose)”
1> 与
1>          [
1> 矩阵类型=特征::矩阵
1>          ]
1>
1> 生成失败。
1>
1> 时间流逝00:00:01.02
=========全部重建:0成功,1失败,0跳过==========

首先检查Eigen的版本,3.2.3及以下版本的运算符*过载似乎有问题。请看 但在我下载了最新版本并使用

Vector2f rotatedVect = t.toRotationMatrix()*v;
成功了

Vector2f rotatedVect = t.toRotationMatrix()*v;