一、前言
点云数据是三维空间中点的集合,广泛应用于计算机视觉、机器人导航和3D建模等领域。其核心在于通过大量离散点描述物体的几何形状。本文的代码旨在解决以下问题:
- 如何从JSON格式中高效读取点云数据;
- 如何利用Python可视化工具展示点云分布;
- 如何对点云数据进行简单过滤(如Z轴值筛选)。
通过该代码,用户可以快速生成点云分布图,并分析不同转速比下的点云特征。
二、整体架构流程
-
模块划分:
Batch_reading
:批量读取JSON文件并绘制点云。single_reading
:单个文件读取、过滤并绘制3D/2D点云。
-
核心流程:
-
数据读取:
with open(f'D:/.../Orthogonal_axis_motor_point_cloud_data_{ num+1}.json', 'r') as file: points_data = json.load(file)
使用
json.load
读取JSON文件,将点云数据加载为Python对象。 -
数据处理:
points_array = np.array(points_data)
将点云数据转换为NumPy数组,便于后续操作。
-
3D绘图:
fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(points_array[:, 0], points_array[:, 1], points_array[:, 2], c='b', marker='o', s=5)
使用Matplotlib绘制3D点云,支持动态标题和网格线显示。
-
过滤与2D投影:
z_0 = 15000 * np.tan(-np.pi / 18) points_array = points_array[points_array[:, 2] >= z_0]
基于Z轴值过滤点云数据,并支持2D投影展示。
-
三、技术细节
-
JSON文件读取:
json包如下:[ [ 0.0, 49.99999999999999, 19.20832241028353 ], [ 0.2277464405828954, 49.99948131289765, 19.2062623555502 ], [ 0.45542715698783337, 49.99792581802448, 19.20008297879511 ], [ 0.6829764678185707, 49.995335213841756, 19.18978664134152 ], [ 0.9103287771569357, 49.991712328319785, 19.1753772753