PCL点云旋转(平面参数)

#include "stdafx.h"
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_cloud.h>
#include <pcl/console/parse.h>
#include <pcl/common/transforms.h>
#include <pcl/visualization/pcl_visualizer.h>
/*输入输入点云,输出点云地址和分割平面方程,返回旋转完的点云,可直接xy面z轴0值分割*/

pcl::PointCloud<pcl::PointXYZRGBA> Rotate(pcl::PointCloud<pcl::PointXYZRGBA> input,double A,double B,double C, pcl::PointCloud<pcl::PointXYZRGBA> &transformed_cloud)
{
    //点云旋转,基于平面标准式法向量原理
    //先绕x旋转,再绕y旋转

    /* Reminder: how transformation matrices work :
    |-------> This column is the translation
    | 1 0 0 x |  \
    | 0 1 0 y |   }-> The identity 3x3 matrix (no rotation) on the left
    | 0 0 1 z |  /
    | 0 0 0 1 |    -> We do not use this line (and it has to stay 0,0,0,1)

    METHOD #1: Using a Matrix4f

    This is the "manual" method, perfect to understand but error prone !

    */

    Eigen::Matrix4f transform_x = Eigen::Matrix4f::Identity();
    /* x转移矩阵
      |1   0   0    |
      |0  cos -sin  |
      |0  sin  cos  |
    */
    double cosx, sinx;
    double dis = sqrt(pow(A, 2) + pow(B, 2) + pow(C, 2));
    cosx = sqrt(pow(A, 2) + pow(C, 2))/dis;
    sinx = B / dis;
    transform_x(1, 1) = cosx;
    transform_x(1, 2) = -sinx;
    transform_x(2,1) = sinx;
    transform_x(2,2) = cosx;

    Eigen::Matrix4f transform_y = Eigen::Matrix4f::Identity();
    /* y转移矩阵
      |cos  0  sin  |
      |0    1   0   |
      |-sin 0  cos  |
    */
    double cosy, siny;
    cosy = C/dis;
    siny = sqrt(pow(A,2)+pow(B,2))/dis;
    // Define a rotation matrix (see https://en.wikipedia.org/wiki/Rotation_matrix)
    transform_y(0, 0) = cosy;
    transform_y(0, 2) = siny;
    transform_y(2, 0) = -siny;
    transform_y(2, 2) = cosy;
    pcl::PointCloud<pcl::PointXYZRGBA> transformedx_cloud;
    pcl::transformPointCloud(input,transformedx_cloud, transform_x);
    pcl::transformPointCloud(transformedx_cloud, transformed_cloud, transform_y);
    return transformed_cloud;

转:PCL点云旋转(平面参数) | 码农家园

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值