机器人坐标系转换从局部坐标系转换到世界坐标系

矩阵方式:
在这里插入图片描述
下面是代码:

#include <Eigen/Dense>

static void transLocalToWorldCloudWith2dPose(const PointCloud &pc_tar, const QPose3f &pose, PointCloud &pc_org) {
    if (pc_tar.empty())
        return;

    PointCloud tmp_pc;
    Eigen::Rotation2Dd R(-pose.yaw);  // 创建旋转矩阵
    Eigen::Vector2d d(pose.x, pose.y);  // 创建平移向量

    for (const auto& point : pc_tar) {
        Eigen::Vector2d local_point(point.x, point.y);
        Eigen::Vector2d world_point = R * local_point + d;  // 进行坐标转换

        tmp_pc.push_back(PointPCL(world_point.x(), world_point.y(), point.z));
    }

    pcl::copyPointCloud(tmp_pc, pc_org);
}

// 在调用此函数时:
transLocalToWorldCloudWith2dPose(pc_tar, pose, pc_org);

函数方式:
在这里插入图片描述
根据三角函数的特性,可以进行一下简化:
在这里插入图片描述

下面是简化前的代码示例:

static void transLocalToWorldCloudWith2dPose(const PointCloud &pc_tar, const QPose3f &pose, PointCloud &pc_org) {
    if (pc_tar.empty())
        return;

    PointCloud tmp_pc;
    for (const auto& point : pc_tar) {
        double world_x;
        double world_y;
        double d_x = point.x * cos(-pose.yaw) + point.y * sin(-pose.yaw);
        double d_y = -point.x * sin(-pose.yaw) + point.y * cos(-pose.yaw);
        world_x = d_x + pose.x;
        world_y = d_y + pose.y;
        tmp_pc.push_back(PointPCL(world_x, world_y, point.z));
    }

    pcl::copyPointCloud(tmp_pc, pc_org);
}

// 在调用此函数时:
transLocalToWorldCloudWith2dPose(pc_tar, pose, pc_org);

最近更新

  1. TCP协议是安全的吗?

    2024-04-14 05:50:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-14 05:50:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-14 05:50:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-14 05:50:03       18 阅读

热门阅读

  1. 新能源汽车动力电池散热技术

    2024-04-14 05:50:03       13 阅读
  2. Node.js 常用命令

    2024-04-14 05:50:03       14 阅读
  3. Vue Router 路由动态缓存组件

    2024-04-14 05:50:03       15 阅读
  4. I/O扩展芯片CAT9532介绍

    2024-04-14 05:50:03       13 阅读
  5. IDE是什么呀

    2024-04-14 05:50:03       12 阅读
  6. HTML5媒体元素

    2024-04-14 05:50:03       16 阅读
  7. Linux上安装Redis

    2024-04-14 05:50:03       19 阅读