gpt4 book ai didi

c++ - 应用于 2 vector 的 Eigen Rotation2D

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:13:14 25 4
gpt4 key购买 nike

我已经在互联网上搜索并阅读了 Eigen 教程,以及所有关于变换、旋转的内容,但我不知道如何将旋转应用于 2 vector 。通常是矩阵 vector 乘积。我正在使用 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();

这就像混淆了需要使用哪个乘法运算符。如果连接或矩阵 vector 乘法。我喜欢这个库,但此时我正在认真地重新考虑在我的项目中使用它。这是我运行代码时 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 ==========

最佳答案

首先检查 Eigen 的版本,看起来 operator* 的重载对于 3.2.3 及以下版本有问题。请看https://forum.kde.org/viewtopic.php?f=74&t=124235&p=326983&hilit=Rotation2D#p326983但是在我下载了最新版本并使用

重新运行我的代码之后
Vector2f rotatedVect = t.toRotationMatrix()*v;

成功了!

关于c++ - 应用于 2 vector 的 Eigen Rotation2D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37443689/

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