Plotting af 3d figure from a given cloud of points

1 view (last 30 days)
We are given reconstructed file and the idea for the assignement is to have the program plotting af figure from a given data set of approx. 32.000 points. The issue is at the moment that the program only plots in a 2d plane and not in a 3d space. Any ideas for a solution to this issue?
Ps: sorry about the danish language in the code
function reconstruct_handout2
% Indlæs data
data = readmatrix( "data.txt" );
n = size(data,1);
% Antal billeder af samme punkt
npoint = 2;
% Vi definere en række konstanter vi bruger
%Vi roterer altid, da vores ksystemer er oftest roteret 90 grader i
%forhold til hinanden
thetax= pi/2
thetaz=thetax
d=0.08
% Rekonstruer punkterne eet adgangen ...
points = [];
for j = 1:5:n
for i = 0:npoint-1
% Hent scannerens konfiguration og punktets koordinater
phi = data(j+i,2);
theta = data(j+i,3);
L = data(j+i,4);
H = data(j+i,5);
xb = data(j+i,6);
yb = data(j+i,7);
% Beregninger ...
Kp= [0;0;0] %Knappenålspunkt
Cp= [xb;yb;-d] %Kamerapunkt
% R1: RotationBordZ
% R2: RotationOmZ
% R3: RotationOmX
% R4: RotationKameraX
R1= [cos(theta), -sin(theta), 0;
sin(theta), cos(theta), 0 ;
0, 0, 1]
R2= [cos(thetaz), -sin(thetaz), 0;
sin(thetaz), cos(thetaz), 0 ;
0, 0, 1]
R3= [1,0,0;
0,cos(thetax),-sin(thetax);
0,sin(thetax),cos(thetax)]
R4= [1,0,0;
0,cos(phi),-sin(phi);
0,sin(phi),cos(phi)];
%Basisskifte flytninging
F= [L;0;H]
%mellemregninger for R1 R2 R3 & R4
%Dette er vores "oneliner"
%R1234 er rotation bord fra mapleopgaven.
R12= R1*R2;
R123= R12*R3;
R1234= R123*R4;
A1= R1234*Cp+F;
K1= R1234*Kp+F;
A11=(1/(sqrt(A1(1)^2+A1(2)^2+A1(3)^2)))*A1;
%Vi laver nogle bereningsmatricer til at løse
%parameterfremstillingen
%P0 og P1 skal nok lige transponeres
%mangler at lave den golden matrice (den grønne matrice i Onenote)
end
%{
Hjælp fra felter
Løsning 2 ligninger 2 ubekendte m. z punktet
vside=[e1x,-e2x;e1y,e2y;e1z,-e2z]
hside=[k2x, -k1x;k2y,-k1y;k2z,-k1z]
t=vside\hside
%}
% Beregninger ...
%Array med x,y,z koordinator for punkterne som er skræingen mellem
%npoint linjer
xnew = []
% Gem det nye punkt
points = [ points; xnew ];
end
% Vis punkt-skyen
figure(1)
scatter3( points(:,1), points(:,2), points(:,3), '.' )
axis equal
% Gem punkt-skyen
writematrix( points, "pointcloud.txt" );

Answers (1)

Sakshay
Sakshay on 1 Dec 2022
Hello Martin,
As per my understanding, you are trying to plot a 3D Point Cloud using MATLAB. You want to create a plot in 3D rather than 2D.
Instead of directly manipulating the 3D points (as done in your code), you can make use of the MATLAB "pointCloud" object to simplify the same. In addition to that, you can use the "pctransform" function to do the relevant transformations on the point cloud data (as done in your code). And, you can also use the "pcshow" function to plot the point cloud in a 3D space. Please refer to the following example code:
% Read data from .txt file
data = readmatrix("data.txt");
% Create Point Cloud object from the point matrix
ptCloud = pointCloud(data);
% Create a transformation object (e.g. 45 degree rotation along the z-axis)
rotationAngles = [0 0 45];
translation = [0 0 0];
tform = rigidtform3d(rotationAngles,translation);
% Transform the point cloud
ptCloudOut = pctransform(ptCloud,tform);
% Plot the transformed point cloud
figure
pcshow(ptCloudOut)
xlabel('X')
ylabel('Y')
zlabel('Z')
Please refer to the following documentations on the functions used for more information on the same:

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!