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

조회 수: 33 (최근 30일)
Raven
Raven 2024년 11월 12일 14:25
답변: Sameer 2024년 11월 13일 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
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