- 'Trisurf' function : https://www.mathworks.com/help/matlab/ref/trisurf.html
Changing the z-location of a 2D triplot
7 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
回答 (1 件)
Shaunak
2025 年 1 月 31 日 11:57
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!
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!