I'm trying to draw a large mesh in Matlab using the trimesh
function, with the z coordinate of the vertices controlling the color. Unfortunately, Matlab stops interpolating colors correctly when the size of the mesh exceeds 120 triangles. Here's a picture demonstrating the problem, with 120 triangles on the left, and 121 triangles on the right.
As you can see, for large meshes, Matlab interpolates directly from the color of one vertex to the color of the other vertex. This was probably done for performance reasons, but I'm trying to generate nice pictures for my thesis, and I don't care how long it takes to compute them. Is there a way to disable this approximation?
Here's the code to generate the picture:
function test(n)
%%% Generate a mesh with n triangles.
oneTriVerts = [0 0 0;
1 0 0;
1 0 1];
offset = [0 (1/n) 0;
0 (1/n) 0;
0 (1/n) 0];
verts = zeros(0,3);
tris = zeros(0,3);
for i = 0:(n-1)
verts = [verts; (oneTriVerts + i * offset)];
tris = [tris; i*3+1, i*3+2, i*3+3];
end
%%% Draw the mesh, with color corresponding to the z coordinate.
trimesh(tris, verts(:,1), verts(:,2), verts(:,3), verts(:,3));
title(sprintf('n = %d', n))
shading interp
axis equal
trimesh
callspatch
, which is a built-in function. As a workaround, could you plot triangles in batches of 100, and then do ahold on
after the first plot? – Bas Swinckelspatch
so this is probably an artifact oftrimesh
changing the call topatch
: mathworks.com/help/matlab/visualize/… – Ben Jacksonn = 100
andn = 300
, and the only differences were the amount of data, and the handle of the parent axes. All the options for vertex shading were the same. – Neil Forrester