点云旋转平移(二)—python open3d点云平移

本文为博主原创文章,未经博主允许不得转载。
本文为专栏《python三维点云从基础到深度学习》系列文章,地址为“https://blog.csdn.net/suiyingy/article/details/124017716”。

点云旋转平移介绍,请参考上一节:点云旋转平移(一)—基础知识介绍_Coding的叶子的博客-CSDN博客

本节所使用的示例pcd点云文件请参考:pcd格式点云样例文件-深度学习文档类资源-CSDN下载

1 python open3d点云平移函数

open3d中点云的平移函数为translate。其函数原型如下所示:

pcd.translate((tx,ty,tz),relative=True)

        当relative为True时,(tx, ty, tz)表示点云平移的相对尺度,也就是平移了多少距离。当relative为False时,(tx, ty, tz)表示点云中心(质心)平移到的指定位置。质心可以坐标可以通过pcd.get_center()得到。

pcd.get_center()<
  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
以下是对点云进行旋转平移的代码示例,假设点云为 $n \times 3$ 的矩阵,表示 $n$ 个点在三维空间中的坐标: ```python import numpy as np def rotate_point_cloud(point_cloud, rotation_matrix): """ 对点云进行旋转 :param point_cloud: 点云矩阵,shape为 (n, 3) :param rotation_matrix: 旋转矩阵,shape为 (3, 3) :return: 旋转后的点云矩阵,shape为 (n, 3) """ return np.dot(point_cloud, rotation_matrix.T) def translate_point_cloud(point_cloud, translation_vector): """ 对点云进行平移 :param point_cloud: 点云矩阵,shape为 (n, 3) :param translation_vector: 平移向量,shape为 (3,) :return: 平移后的点云矩阵,shape为 (n, 3) """ return point_cloud + np.tile(translation_vector, (point_cloud.shape[0], 1)) # 假设需要对点云进行旋转平移 point_cloud = np.random.rand(100, 3) # 生成100个点的点云 rotation_matrix = np.array([[1, 0, 0], [0, 0, -1], [0, 1, 0]]) # 绕 y 轴逆时针旋转90度 translation_vector = np.array([0, 1, 0]) # 沿 y 轴正方向平移1个单位 # 旋转 rotated_point_cloud = rotate_point_cloud(point_cloud, rotation_matrix) # 平移 translated_point_cloud = translate_point_cloud(rotated_point_cloud, translation_vector) ``` 值得注意的是,旋转矩阵 $R$ 的转置 $R^T$ 表示的是从旋转后的坐标系到旋转前的坐标系的变换,因此需要对点云矩阵 $P$ 执行 $P \times R^T$ 的矩阵乘法。另外,平移向量需要按行复制成和点云矩阵相同的形状,然后和点云矩阵相加。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Coding的叶子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值