- 为了对点云进行旋转操作,达到各点云之间不对齐的效果,找到了生成点云绕任意轴旋转的矩阵的代码。
链接: https://blog.csdn.net/u010848251/article/details/56679649?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-8.control&dist_request_id=&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-8.control.
#include <Eigen/Core>
#include<iostream>
#include<vector>
Eigen::Matrix4f rot_mat(const Eigen::Vector3f& point, const Eigen::Vector3f& vector, const float t)
{
float u = vector(0);
float v = vector(1);
float w = vector(2);
float a = point(0);
float b = point(1);
float c = point(2);
Eigen::Matrix4f matrix;
std::cout << float(cos(t))<<std::endl;
matrix<<u*u + (v*v + w*w)*cos(t), u*v*(1 - cos(t)) - w*sin(t), u*w*(1 - cos(t)) + v*sin(t), (a*(v*v + w*w) - u*(b*v + c*w))*(1 - cos(t)) + (b*w - c*v)*sin(t),
u*v*(1 - cos(t)) + w*sin(t), v*v + (u*u + w*w)*cos(t), v*w*(1 - cos(t)) - u*sin(t), (b*(u*u + w*w) - v*(a*u + c*w))*(1 - cos(t)) + (c*u - a*w)*sin(t),
u*w*(1 - cos(t)) - v*sin(t), v*w*(1 - cos(t)) + u*sin(t), w*w + (u*u + v*v)*cos(t), (c*(u*u + v*v) - w*(a*u + b*v))*(1 - cos(t)) + (a*v - b*u)*sin(t),
0, 0, 0, 1;
return matrix;
}
int main(int argc, char** argv) {
Eigen::Vector3f point = {5.7,1.8,-77};
Eigen::Vector3f axis={0,1,0};
Eigen::Matrix4f a=rot_mat(point,axis,(3.14/36));
std::cout<< a << std::endl;
return 0;
}
- 为了让点云能够绕自身中心旋转,需要读取点云近似中心点的坐标,找到了open3d交互式显示点云的代码。
链接: https://blog.csdn.net/u014072827/article/details/113765847.
python:
pcd9 = o3d.io.read_point_cloud('fragment_018.pcd')
vis = o3d.visualization.VisualizerWithEditing()
vis.create_window()
vis.add_geometry(pcd9)
vis.run()
vis.destroy_window()