Hi Elisa,
To achieve the extraction of profiles from the rotated 3D point cloud, I had to follow a series of steps after rotating the data to align with the maximum slope direction. Here's an updated version of the code that includes the extraction of profiles.
load('XYZ');
X = XYZ(:,1);
Y = XYZ(:,2);
Z = XYZ(:,3);
xyz0 = mean(XYZ,1);
A = XYZ - xyz0; % Center the data at zero
% Find the direction of most variance using SVD and rotate the data to make that the x-axis
[~, ~, V] = svd(A, 0);
a = cross(V(:,3), [0;0;1]);
T = makehgtform('axisrotate', a, -atan2(norm(a), V(3,3)));
R = T(1:3,1:3);
A_rot = A * R;
A_rot = A_rot + [xyz0(1) xyz0(2) 0]; % Move so the centers are aligned in the z-direction
% Extract profiles along vertical planes oriented based on the maximum slope
% Maximum slope direction
max_slope_direction = V(:,3);
% Fixed distance for profile extraction
fixed_distance = 0.1;
profiles = cell(1, size(A_rot, 1));
for i = 1:size(A_rot, 1) profile_points = A_rot(i, :); profile_points = repmat(profile_points, size(A_rot, 1), 1); distances = sqrt(sum((A_rot - profile_points).^2, 2)); [~, sorted_indices] = sort(distances); profile = A_rot(sorted_indices(2:end), :); % Exclude the point itself profiles{i} = profile; end
% Plot the extracted profiles
figure;
hold on;
for i = 1:size(profiles, 2) scatter3(profiles{i}(:,1), profiles{i}(:,2), profiles{i}(:,3), 0.1, 'green'); end
xlabel('X-Axis', 'FontSize', 14, 'FontWeight', 'bold');
ylabel('Y-Axis', 'FontSize', 14, 'FontWeight', 'bold');
zlabel('Z-Axis', 'FontSize', 14, 'FontWeight', 'bold');
axis equal;
So, first I needed to determine the maximum slope direction from the rotated data. Then, iterate through each point in the rotated cloud, extract profiles at a fixed distance, and plot these extracted profiles which makes sure that profiles are extracted along vertical planes oriented according to the maximum slope of the cloud.
I just tried to execute the code utilizing your XYZ.mat file but my MATLAB session kept disconnected. Please see attached.
So, I need your help to execute the code and let me know if this helps resolve your problem. Thanks for your cooperation.