How to convert point cloud in vectors
15 次查看(过去 30 天)
显示 更早的评论
Hi guys!
I have a point cloud that define an object. Image that my point cloud is defining one monitor (screen). Firstly, I want to delete all the unecessary points to define my screen, for example, the four points of the corners is enough. But what I really want later is the screen defined by vectors.
How can I do that?
I already have the point cloud with multiple points.
回答(1 个)
VINAYAK LUHA
2023-10-1
编辑:VINAYAK LUHA
2023-10-1
Hi Fabio,
I understand that you want to do the followings:
- Obtain a screen (a plane) defined by some points in your 3D point cloud.
- Define the plane so obtained in vector format.
Here are some pointers to achieve your target:
- Use any three known points on the plane to find two vectors at a common point.
- Use the cross product of these two vectors to find the normal to the plane (vectorN).
- Separate the points not lying on the plane based on the distance of the points from the defined plane.
- Now the plane can be expressed in vector format as (vectorR-vectorA).vectorN=0, where vectorR is any arbirtary vector from origin to the plane and vectorA is position vector of one of the known point on the plane.
Here is the code snippet for your refernce:
% Generate a point cloud
numPoints = 1000;
pointCloud=rand(numPoints,3);
% Select three points to define the plane
planeIndices = randperm(numPoints, 3);
plane3Points = pointCloud(planeIndices, :);
% Define the plane using the selected points
planeNormal = cross(plane3Points(2, :) - plane3Points(1, :), plane3Points(3, :) - plane3Points(1, :));
planeNormal = planeNormal / norm(planeNormal);
planeD = dot(planeNormal, plane3Points(1, :));
% Calculate the distances of all points to the plane
distances = zeros(numPoints, 1);
for i = 1:numPoints
distances(i) = abs(dot(planeNormal, pointCloud(i, :)) - planeD);
end
% Set a threshold to identify points on the plane
threshold = 0.01;
planeIndices = distances < threshold;
planeAllPoints = pointCloud(planeIndices, :);
% Plotting the point cloud
scatter3(pointCloud(:, 1), pointCloud(:, 2), pointCloud(:, 3), '.');
hold on
patch('Faces', 1:3, 'Vertices', plane3Points, 'FaceColor', 'g', 'FaceAlpha', 0.5);
hold off
title('Point Cloud');
% Plotting the plane points
scatter3(planeAllPoints(:, 1), planeAllPoints(:, 2), planeAllPoints(:, 3), 'r.');
hold on
patch('Faces', 1:3, 'Vertices', plane3Points, 'FaceColor', 'g', 'FaceAlpha', 0.5);
hold off
title('Points On The Plane');
Hope this helps
Regards,
Vinayak Luha
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Point Cloud Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!