Reputation: 638
Usually, trisurf is used to plot nodal quantity on a triangular mesh. However, I would like to plot some element-wise quantity using the following command.
trisurf(t,p(:,1),p(:,2),elewise_quantity,'edgecolor','k','facecolor','interp');
Where elewise_quantiy should be of the same dimension as p(:,1) or p(:,2), so I create elewise_quantity by associating the element-wise quantity to each node of that element.
In this specific case, the 8 triangular element in the middle are associated with 1 and all other elements are 0-valued. There are 10*10 little squares and 10*10*2 little triangulars.
The problem is, as shown in the picture, trisurf can't produce the effect I want. What I expect is an "exact element-wise description", i.e sharp transition at the edge
Also notice that at each corner, the display is different, this's due to the specific orientation of the triangular, is there an elegant way to deal with it?
Upvotes: 0
Views: 1265
Reputation: 6084
You can set per-triangle colors using this method:
%// Example data
X = rand(100,1);
Y = rand(100,1);
Z = X+Y;
T = delaunay(X,Y);
C = mean(Z(T),2);
%// Plot the data
hh = trisurf(T,X,Y,Z);
set(gca, 'CLim', [min(C), max(C)]);
set(hh,'FaceColor', 'flat', ...
'FaceVertexCData', C, ...
'CDataMapping', 'scaled');
If you also don't want the see the triangles that appear at the boundary, you won't get this behavior from a single call to trimesh
. You would need to compute a per-triangle quantity and then drop those you don't want to plot according to the per-triangle quantity.
Upvotes: 0
Reputation: 308848
If you need sharp discontinuities across elements, I'd recommend not displaying nodal values. Calculate element values at internal integration points (e.g. element average at centroid) and assign that value to the element. Ask Matlab to color each element according to its centroidal or integration point value.
Upvotes: 1