0

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?


enter image description here

lorniper
  • 626
  • 1
  • 7
  • 29
  • Mmmm this is tricky. The data between points is linearly interpolated by the plot function. If you want to show that "sharp" edge between both you need to insert in the plotting matrix a new rowof data with the same X,Y of the "high" points and the Z values of the "low" points. This can be easy for something like your example, but for "general" surfaces.... ufff. what I did when I wanted that effet is to interpolate you data from 10x10 to 100x100. It kinda gets that effect. – Ander Biguri Jul 04 '14 at 14:50
  • @AnderBiguri Yeah, I am also using a finer mesh. a little dirty... – lorniper Jul 04 '14 at 16:01

2 Answers2

1

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.

duffymo
  • 305,152
  • 44
  • 369
  • 561
0

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.

knedlsepp
  • 6,065
  • 3
  • 20
  • 41