matlab - 如何改变点云中平面的位置?
问题描述
我在一个文本文件中有 x,y,z 坐标,我从中创建了一个圆柱形式的点云。我想插入一个平面以便仅提取某些点(交叉点云和平面)以便稍后评估它们。我已经可以编写代码来沿 z 轴插入一个平面。我使用了此处发布的代码作为基础,我根据自己的目的进行了调整。我现在的问题是飞机在我对数据感兴趣的地方没有与点云相交。我已经尝试围绕 z 轴旋转点云,这改变了平面的位置,但它也改变了点云的形状,因此它不再看起来像圆柱体。我现在的问题是,是否有可能在不改变点云形状的情况下改变平面的位置?这就是我正在使用的代码:
filename = 'C:\Users\file location\plane.txt';
fileID = fopen(filename, 'r');
%% Read text file as columns and convert cell array into a matrix
ptCloud = cell2mat(textscan(fileID, '%f%f%f','delimiter',',','collectoutput',1));
%Separate matrix into x,y,z
x = ptCloud(:,1);
y = ptCloud(:,2);
z = ptCloud(:,3);
%% Create the plane
p0 = [0 0 0];
p1 = [0 max(y(:)) 0];
p2 = [0 0 max(z(:))];
% normal vector of a plane
n = cross(p0-p1,p0-p2);
n = n/norm(n);
% equation of a plane
% a(x-x0) + b(y-y0) + c(z-z0) = 0
F = @(X,Y) -n(1)/n(3)*(X-p0(1)) - n(2)/n(3)*(Y-p0(2)) + p0(3);
[x0,y0] = meshgrid([min(z(:)) max(z(:))]);
z0 = F(x0,y0);
% find distance to plane for each point
% (using the same formula)
FDIST = @(X,Y,Z) sum(n.*(p0-[X Y Z]));
D = arrayfun(FDIST,x(:),y(:),z(:),'uni',false);
D1 = cell2mat(D);
mindist = 1; % minumum distance to plane
ind = abs(D1) < mindist;
mplot = @(p,s) plot3(p(1),p(2),p(3),s);
plot3(x(:),y(:),z(:),'.b') % all data
hold on
plot3(x(ind),y(ind),z(ind),'or') % points belong to plane
% original points
mplot(p1,'^k')
mplot(p2,'^k')
mplot(p0,'^k')
surf(x0,y0,z0,'FaceAlpha',0.5); % plane
xlabel('X(mm)')
ylabel('Y(mm)')
zlabel('Z(mm)')
title('Plane in point cloud')
hold off
axis equal
我已经尝试通过这样做来围绕 z 轴旋转点云。
x = x*cos(theta) - y*sin(theta);
y = x*sin(theta) + y*cos(theta);
z = z;
为了更好地理解,您可以在下图中看到带有平面的点云当前的样子。
解决方案
推荐阅读
- bash - 如果需要,有没有办法在 bash 中查找文件、移动和重命名?
- r - 如何在保存所做编辑的同时将行添加到 DT 包
- c# - 需要以某种方式抵消玩家的移动
- json - Clikhouse + Amazon SNS 通知
- google-apps-script - 用于非规范化 json 数据工作不正常的 Google Apps 脚本功能
- sql - 使用 FUNCTION -SQL Server 查询查找员工的当前职位
- php - Shopware : 通过 ID 获取文件编号
- arrays - 如何在 MATLab 中创建增量为 0.01 的样本直方图?
- prometheus - 使用 grafana 持续时间变量重新采样普罗米修斯数据
- javascript - How can I change the collisionFilter of an object so it can no longer interact with MouseConstraint (MatterJS)