Changing the z-location of a 2D triplot

5 visualizaciones (últimos 30 días)
Pieter
Pieter el 14 de Abr. de 2013
Respondida: Shaunak el 31 de En. de 2025
Good day,
I have the following code:
numx=3;
numy=3;
xgrid=0:(1/numx):1;
ygrid=0:(1/numy):1;
[X,Y] = meshgrid(xgrid,ygrid);
DT = DelaunayTri(X(:),Y(:));
triplot(DT)
Which works fine.
I am combing this 2D plot together with a 3D plot. Now I would like to shift the triplot from z=0 to some other z value, for example z=-1.
Can anyone tell me how to achieve this?
Thank you in advance!

Respuestas (1)

Shaunak
Shaunak el 31 de En. de 2025
Hello Pieter,
You can shift your 2D ‘triplot’ into a 3D space by using the ‘trisurf’ function in MATLAB.
This function allows you to specify a constant z-value for the vertices of the triangles, effectively lifting your plot to a specified z-level.
Here's a simple way to achieve this:
% Define the grid resolution
numx = 3;
numy = 3;
% Create grid points
xgrid = 0:(1/numx):1;
ygrid = 0:(1/numy):1;
[X, Y] = meshgrid(xgrid, ygrid);
% Create Delaunay triangulation
DT = delaunayTriangulation(X(:), Y(:));
% Define the z-value where you want to shift the triplot
zValue = -1;
% Create a z-coordinate array of the same size as X and Y, filled with zValue
Z = zValue * ones(size(X(:)));
% Plot the triangulation using trisurf, which allows you to specify Z
trisurf(DT.ConnectivityList, X(:), Y(:), Z, 'FaceColor', 'cyan', 'EdgeColor', 'black');
% Optionally, adjust the view to see the 3D effect
view(3);
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Shifted Triplot in 3D');
grid on;
The above implementation shifts your 2D triangulation plot to the specified z-value in 3D space, allowing you to integrate it with other 3D plots.
For more information on the 'trisurf' function, you can refer to this link:
Hope this helps!

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by