Triangular mesh between points

1 次查看(过去 30 天)
Ahmed
Ahmed 2023-8-22
回答: Vinayak 2024-1-4
I have the XYZ coordinates of a set of points if joined create the shape shown in the image, i was thinking of copying this array and changing the Z Value to generate the exact same shape at a different Z value. But i need help in generating a triangular mesh between these two shapes similar to the image attached

回答(1 个)

Vinayak
Vinayak 2024-1-4
Hi Ahmed,
As you have not attached the images or data, the below code assumes you have a shape with 10 points in the form of a 10X3 matrix. I modifed the third column (z-index) while creating a new shape.
I have used delaunayTriangulation to generate the connections and plotted using a tetramesh.
% Sample Shape (Decagon)
theta = linspace(0, 2*pi, 10); % 10 points to create the star
radius1 = 1;
x1 = radius1 * cos(theta);
y1 = radius1 * sin(theta);
z1 = zeros(size(x1)); % Set a constant height for Shape 1
shape1 = [x1', y1', z1'];
% Slightly modify Z values for Shape 2
shape2 = shape1;
shape2(:, 3) = shape2(:, 3) + 5 * rand(size(shape1, 1), 1);
% Combine points
combinedPoints = [shape1; shape2];
triangulation = delaunayTriangulation(combinedPoints(:, 1), combinedPoints(:, 2), combinedPoints(:, 3));
% Plot the original shapes
figure;
scatter3(shape1(:, 1), shape1(:, 2), shape1(:, 3), 'r', 'filled');
hold on;
scatter3(shape2(:, 1), shape2(:, 2), shape2(:, 3), 'b', 'filled');
tetramesh(triangulation,'FaceAlpha',0.1);

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by