Eigen:几何变换

本文详细介绍了Eigen库在处理几何变换中的使用方法,包括矩阵运算、向量操作以及如何应用于旋转、平移等常见几何操作。通过实例解析,展示了Eigen如何简化3D空间中的数学计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

笔记

题目:
/*
已知旋转矩阵定义是沿着Z轴旋转45°。请按照该定义初始化旋转向量、旋转矩阵、四元数、欧拉角。请编程实现:
1、以上四种表达方式的相互转换关系并输出
2、假设平移向量为(1,2,3),请输出旋转矩阵和该平移矩阵构成的欧式变换矩阵,并根据欧式变换矩阵提取旋转向量及平移向量
本程序学习目标:
1、学习eigen中刚体旋转的四种表达方式,熟悉他们之间的相互转换关系
2、熟悉旋转平移和欧式变换矩阵的相互转换关系
*/

#include <iostream>
#include <cmath>
#include <eigen3/Eigen/Core>
#include <eigen3/Eigen/Geometry>

using std::cout;
using std::endl;

int main(int argc, char **argv) {
   
   
  // 定义绕Z轴旋转45°的旋转向量
  Eigen::AngleAxisd rotationVector(M_PI / 4, Eigen::
guo@guo-Dell-G15-5520:~/g2o仿真/src/build$ make Consolidate compiler generated dependencies of target g2o_demo [ 50%] Building CXX object CMakeFiles/g2o_demo.dir/optimize.cc.o /home/guo/g2o仿真/src/optimize.cc: In function ‘std::vector<Eigen::Transform<double, 3, 1> > generateNoisyTrajectory(int)’: /home/guo/g2o仿真/src/optimize.cc:73:44: error: expected primary-expression before ‘(’ token 73 | Quaterniond noise_rot = Quaterniond(AngleAxisd( | ^ /home/guo/g2o仿真/src/optimize.cc:75:32: error: expected ‘)’ before ‘;’ token 75 | Vector3d::UnitZ())); | ^ | ) /home/guo/g2o仿真/src/optimize.cc:73:44: note: to match this ‘(’ 73 | Quaterniond noise_rot = Quaterniond(AngleAxisd( | ^ /home/guo/g2o仿真/src/optimize.cc: In function ‘int main()’: /home/guo/g2o仿真/src/optimize.cc:162:9: error: ‘Matrix6d’ was not declared in this scope 162 | Matrix6d info = Matrix6d::Identity(); | ^~~~~~~~ /home/guo/g2o仿真/src/optimize.cc:163:30: error: ‘info’ was not declared in this scope 163 | edge->setInformation(info); | ^~~~ /home/guo/g2o仿真/src/optimize.cc:178:5: error: ‘Matrix6d’ was not declared in this scope 178 | Matrix6d loopInfo = Matrix6d::Identity() * 10.0; | ^~~~~~~~ /home/guo/g2o仿真/src/optimize.cc:179:30: error: ‘loopInfo’ was not declared in this scope 179 | loopEdge->setInformation(loopInfo); | ^~~~~~~~ In file included from /usr/local/include/eigen3/Eigen/Geometry:42, from /home/guo/g2o仿真/src/optimize.cc:4: /usr/local/include/eigen3/Eigen/src/Geometry/Quaternion.h: In instantiation of ‘Derived& Eigen::QuaternionBase<Derived>::operator=(const Eigen::MatrixBase<OtherDerived>&) [with OtherDerived = Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Matrix<double, 3, 1> >, const Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, 3, 3> >, 3, 1, false> >; Derived = Eigen::Quaternion<double>]’: /usr/local/include/eigen3/Eigen/src/Geometry/Quaternion.h:313:90: required from ‘Eigen::Quaternion<Scalar, Options>::Quaternion(const Eigen::MatrixBase<OtherDerived>&) [with Derived = Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Matrix<double, 3, 1> >, const Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, 3, 3> >, 3, 1, false> >; _Scalar = double; int _Options = 0]’ /usr/local/include/eigen3/Eigen/src/Geometry/AngleAxis.h:201:18: required from ‘Eigen::AngleAxis<_Scalar>& Eigen::AngleAxis<Scalar>::operator=(const Eigen::MatrixBase<OtherDerived>&) [with Derived = Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Matrix<double, 3, 1> >, const Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, 3, 3> >, 3, 1, false> >; _Scalar = double]’ /usr/local/include/eigen3/Eigen/src/Geometry/AngleAxis.h:88:85: required from ‘Eigen::AngleAxis<Scalar>::AngleAxis(const Eigen::MatrixBase<OtherDerived>&) [with Derived = Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Matrix<double, 3, 1> >, const Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, 3, 3> >, 3, 1, false> >; _Scalar = double]’ /home/guo/g2o仿真/src/optimize.cc:75:31: required from here /usr/local/include/eigen3/Eigen/src/Geometry/Quaternion.h:583:59: error: incomplete type ‘Eigen::internal::quaternionbase_assign_impl<Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Matrix<double, 3, 1> >, const Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, 3, 3> >, 3, 1, false> >, 3, 1>’ used in nested name specifier 583 | internal::quaternionbase_assign_impl<MatrixDerived>::run(*this, xpr.derived()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ make[2]: *** [CMakeFiles/g2o_demo.dir/build.make:76:CMakeFiles/g2o_demo.dir/optimize.cc.o] 错误 1 make[1]: *** [CMakeFiles/Makefile2:673:CMakeFiles/g2o_demo.dir/all] 错误 2 make: *** [Makefile:146:all] 错误 2 guo@guo-Dell-G15-5520:~/g2o仿真/src/build$
最新发布
08-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值