Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-11-27, 18:11   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
默认 如何在点云中更改平面的位置?

我在一个文本文件中具有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-[XYZ])); 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; 为了更好地理解,您可以在下图上看到带有平面的点云的当前外观。





更多&回答...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 21:35


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.