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

31 Ansichten (letzte 30 Tage)
Raven
Raven am 12 Nov. 2024 um 14:25
Beantwortet: Sameer am 13 Nov. 2024 um 6:06
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 Kommentar
Matt J
Matt J am 13 Nov. 2024 um 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sameer
Sameer am 13 Nov. 2024 um 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!

Kategorien

Mehr zu Delaunay Triangulation finden Sie in Help Center und File Exchange

Produkte


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by