How to convert point cloud in vectors
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Réponses (1)
VINAYAK LUHA
le 1 Oct 2023
Modifié(e) : VINAYAK LUHA
le 1 Oct 2023
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 commentaires
Voir également
Catégories
En savoir plus sur Point Cloud Processing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!