cartographer源码分析(13)-transform-rigid_transform.h

本文深入剖析了cartographer库中transform-rigid_transform.h源码,探讨了其在SLAM中的作用,提供了下载链接以及作者在多个平台的发布地址。

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

源码可在https://github.com/learnmoreonce/SLAM 下载


#ifndef CARTOGRAPHER_TRANSFORM_RIGID_TRANSFORM_H_
#define CARTOGRAPHER_TRANSFORM_RIGID_TRANSFORM_H_

#include <iostream>
#include <string>

#include "Eigen/Core"
#include "Eigen/Geometry"
#include "cartographer/common/lua_parameter_dictionary.h"
#include "cartographer/common/math.h"
#include "cartographer/common/port.h"

namespace cartographer {
namespace transform {

/*
几个名词细微的区别 :

transformation:变换
translation:平移
rotation:旋转
scaling:缩放
counter clock wise rotation:逆时针旋转,counter:反向
Identity():单位矩阵,不同于线性代数的“单位”。在不同的语义下,含义会不同。


Rigid2是对二维刚性变换【旋转与平移】的封装,SE2.对应论文公式(1):


Rigid2表现为先将vector[x0,y0]旋转θ角度得到[x',y'],然后再叠加[dx,dy]得到[x1,y1]
即:
x1=x'+dx,
y1=y'+dy,


模板参数必须是浮点型。(int类型为错误用法)

提供2个操作:
1,按照指定角度θ逆时针旋转。此时dx,dy=0
2,按照指定平移向量dx,dy平移. 此时θ=0

静态成员函数包括:
1,Rotation()
2,Translation()
3,Identity()

Translation()指定对象的2D translation(2D平移)。
第一个参数对应X轴,第二个参数对应Y轴。默认是单位变换。   


[x'       [cosθ , -sinθ           [ x
 y']   =   sinθ ,  cosθ ]   *       y ]

*/
template <typename FloatType> 
//FloatType不能是int类型,不然Rotation2D的cos0==0,丢失角度信息,无法得到正确结果
class Rigid2 {
 public:
  using Vector = Eigen::Matrix<FloatType, 2, 1>;//2行1列,p142
  using Rotation2D = Eigen::Rotation2D<FloatType>;

// 无参构造函数,平移向量为单位向量[1,0]^t,旋转角度为0,debugstring()输出:[1,0,0]
  Rigid2()
      : translation_(Vector::Identity()), rotation_(Rotation2D::Identity()) {}


//Rotation2D(double ): Construct a 2D counter clock wise rotation from the angle a in radian. 

//双参构造函数,给定平移向量[dx,dy]和旋转角度0,进行旋转变换:  
  Rigid2(const Vector& translation, const Rotation2D& rotation)
      : translation_(translation), rotation_(rotation) {}
//同上,给定旋转角度θ,double是弧度值。
  Rigid2(const Vector& translation, const double rotation)
      : translation_(translation), rotation_(rotation) {}

//类的静态成员函数,返回Rigid2,debugstring()是[0,0,θ ]
  static Rigid2 Rotation(const double rotation) { //给定旋转角度θ 
    return Rigid2(Vector::Zero(), rotation);
  }
//同上
  static Rigid2 Rotation(const Rotation2D& rotation) {
  //给定旋转矩阵,角度为θ 
    return Rigid2(Vector::Zero(), rotation);
  }
//旋转角度是单位矩阵,即θ为0 ,[dx,dy,0]
  static Rigid2 Translation(const Vector& vector) { 

    return Rigid2(vector, Rotation2D::Identity());//θ为0
  }

//静态成员函数,全为0:
  static Rigid2<FloatType> Identity() {    //返回Rigid2,[0,0,0]
    return Rigid2<FloatType>(Vector::Zero(), Rotation2D::Identity());
  }

/*为什么要加translation_.template:
参见成员模板函数的写法:
https
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值