How to create a triangle mesh for surface with duplicate x.y values?

31 次查看(过去 30 天)
I am trying to create a triangle mesh for a surface I am working with. I started by trying to use
dt = delaunayTriangulation(x,y);
tri = triangulation(dt.ConnectivityList, x, y, z);
However, this doesn't work, as the surface I'm working with contains points that have the same x,y coordinates, but different z coordinates. When I run the Delaunay triangulation on the x and y coordinates, it simply ignores what it sees as duplicate points, and leads to an incorrect answer when I run the second line. Running it with any other pair of coordinates (x,z or y,z) would yield the same problem. If I run it with all 3 coordinates, then it generates a 3D Delaunay triangulation made up of tetrahedrons, which isn't what I want either, since I want to work with a surface mesh. How can I generate such a mesh in MATLAB?
  1 个评论
Matt J
Matt J 2024-11-13,5:23
Not enough information. If you have multiple z corresponding to the same (x,y) then clearly your surface cannot have the functional form z(x,y). We need to know what functional form it is supposed to have, or what other considerations are to decide the connections of the points.

请先登录,再进行评论。

回答(1 个)

Sameer
Sameer 2024-11-13,6:06
To generate a surface mesh from a set of points where multiple points may share the same (x, y) coordinates but have different z values, you need to approach the problem by considering the surface as a collection of 2D projections with an additional dimension for height.
1. Since the problem arises from having multiple z values for the same ( x, y) pair, you need to handle these points carefully. One way is to average the z values or select the relevant z value for your surface.
2. Perform a "Delaunay triangulation" on the unique (x, y) points.
3. Use the "triangulation" to map back to your 3D surface by assigning the corresponding z values to the (x, y) points.
Here's a sample code:
x = [1, 1, 2, 2, 3, 3, 1.5]';
y = [1, 1, 2, 2, 3, 3, 2]';
z = [1, 2, 1, 3, 1, 4, 2.5]';
points = [x, y, z];
% Find unique (x, y) pairs, and their indices
[uniqueXY, ~, idx] = unique(points(:, 1:2), 'rows');
% Calculate the mean z-value for each unique (x, y)
uniqueZ = accumarray(idx, points(:, 3), [], @mean);
% Perform Delaunay triangulation on the unique (x, y) points
dt = delaunayTriangulation(uniqueXY);
% Check if the triangulation is valid
if isempty(dt.ConnectivityList)
error('The triangulation is empty. Ensure that the points are not collinear.');
end
% Create a 3D triangulation object
tri = triangulation(dt.ConnectivityList, uniqueXY(:, 1), uniqueXY(:, 2), uniqueZ);
% Visualize the corrected surface mesh
trisurf(tri);
xlabel('X');
ylabel('Y');
zlabel('Z');
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Delaunay Triangulation 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by