3D Delaunay triangulation set constraint on free boundary
Show older comments
I am trying to create and visualise the envelope of an unstructured point cloud that has been measured using a structured approach:
There measurements are made in spherical coordinates and map a half sphere. From that I am able to find the connectivity of the free boundary. I would like to apply that constraint on the measurement (the half sphere is deformed by the measured distance)
I have scratched the script below but I cannot figure out how to apply the constraint.
I am also trying other methods such as alphaShape, but without success.
clear all;close all;clc
load myData.mat
% sphere 2 cart
[x,y,z] = createPointCloud(alphaAngle, betaAngle,Distance);
% sphere 2 cart
[xU,yU,zU] = createPointCloud(alphaAngle, betaAngle,ones(length(alphaAngle),1));
figure
ax1(1) = subplot(2,2,1);
scatter3(ax1(1),xU,yU,zU,10,'blue',MarkerFaceColor='flat');
set(gca,'DataAspectRatio',[1 1 1]);xlabel('X (m)');ylabel('Y (m)');zlabel('Z (m)');view(3);
ax1(2) = subplot(2,2,2);
scatter3(ax1(2),x,y,z,10,'blue',MarkerFaceColor='flat');
set(gca,'DataAspectRatio',[1 1 1]);xlabel('X (m)');ylabel('Y (m)');zlabel('Z (m)');view(3);
% triangulation of the half sphere
DTU = delaunayTriangulation(xU,yU,zU);
ax1(3) = subplot(2,2,3);
scatter3(ax1(3),xU,yU,zU,10,'blue',MarkerFaceColor='flat'); hold on
trisurf(DTU.freeBoundary,DTU.Points(:,1),DTU.Points(:,2),DTU.Points(:,3),0.05,'FaceAlpha',0.05,'FaceColor','blue');
% triangulation of the measurement point
DT = delaunayTriangulation(x,y,z);
ax1(4) = subplot(2,2,4);
scatter3(ax1(4),x,y,z,10,'blue',MarkerFaceColor='flat'); hold on
trisurf(DT.freeBoundary,DT.Points(:,1),DT.Points(:,2),DT.Points(:,3),0.05,'FaceAlpha',0.05,'FaceColor','blue');
linkprop(ax1, {'View'})
% get constraint to apply on the 3D triangulation
FU = DTU.freeBoundary;
% how to apply the constraint to the measurement data?
function [x,y,z] = createPointCloud(alphaAngle, betaAngle,Distance)
rho = Distance;
phi = pi/2-alphaAngle;
theta = betaAngle;
x = rho .* sin(phi) .* cos(theta);
y = rho .* sin(phi) .* sin(theta);
z = rho .* cos(phi);
x = [x',x']';
y = [y',-y']';
z = [z',z']';
input= [x y z] ;
output = unique(input,'rows');
x = output(:,1);
y = output(:,2);
z = output(:,3);
end
Answers (1)
Prathamesh
on 3 Mar 2025
Hi Sylvain, I understand that you are trying to visualise the envelope of an unstructured point cloud. The measurements are made in spherical coordinates and map a half sphere. The connectivity of the free boundary has been successfully found. So now you want to apply constraint on the measurement.
Solution:
- Convert spherical to Cartesian coordinates for both datasets for 3D visualization.
- Use Delaunay triangulation on undeformed data to find its free boundary.
- Visualize the undeformed half-sphere and its boundary as a reference.
- Use ‘alphaShape’ to create a smooth outline around deformed data; adjust ‘alphaVal’ for detail.
While direct application of boundary constraints to the deformed data is complex, the alpha shape provides a smooth approximation of the envelope, respecting the original structure's general shape.
Below is the code with comments provided where necessary.
clear all; close all; clc;
load myData.mat
% Convert spherical coordinates to Cartesian coordinates
[x, y, z] = createPointCloud(alphaAngle, betaAngle, Distance);
[xU, yU, zU] = createPointCloud(alphaAngle, betaAngle, ones(size(Distance)));
% Triangulate the undeformed point cloud
DTU = delaunayTriangulation(xU, yU, zU);
FU = DTU.freeBoundary; % Extract free boundary
% Visualize the undeformed point cloud and its boundary
figure;
subplot(1, 2, 1);
trisurf(FU, xU, yU, zU, 'FaceColor', 'cyan', 'EdgeColor', 'none', 'FaceAlpha', 0.5);
hold on;
scatter3(xU, yU, zU, 10, 'blue', 'filled');
title('Undeformed Half-Sphere');
xlabel('X'); ylabel('Y'); zlabel('Z');
axis equal; view(3);
% Visualize the deformed point cloud
subplot(1, 2, 2);
scatter3(x, y, z, 10, 'red', 'filled');
title('Deformed Measurement Points');
xlabel('X'); ylabel('Y'); zlabel('Z');
axis equal; view(3);
% Create an alpha shape to visualize the envelope of the deformed data
alphaVal = 1.5; % Adjust this value as needed
shp = alphaShape(x, y, z, alphaVal);
% Plot the alpha shape
figure;
plot(shp, 'FaceColor', 'green', 'EdgeColor', 'none', 'FaceAlpha', 0.5);
hold on;
scatter3(x, y, z, 10, 'red', 'filled');
title('Alpha Shape of Deformed Data');
xlabel('X'); ylabel('Y'); zlabel('Z');
axis equal; view(3);
function [x, y, z] = createPointCloud(alphaAngle, betaAngle, Distance)
% Convert spherical coordinates (alpha, beta, Distance) to Cartesian coordinates (x, y, z)
rho = Distance;
phi = pi/2 - alphaAngle;
theta = betaAngle;
x = rho .* sin(phi) .* cos(theta);
y = rho .* sin(phi) .* sin(theta);
z = rho .* cos(phi);
% Ensure unique points
input = [x, y, z];
output = unique(input, 'rows');
x = output(:, 1);
y = output(:, 2);
z = output(:, 3);
end
screenshot of my output

Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!