trimesh
Creates a 3D triangulated mesh.
Syntax
h = trimesh(tri, x, y, z)
h = trimesh(tri, x, y, cdata)
h = trimesh(tri, x, y)
h = trimesh(..., property, value, ...)
h = trimesh(hAxes, ...)
Inputs
- tri
- An Mx3 matrix, where M is the number of triangles. Each row contains the indices of a triangle in the x, y and z matrices. Usually, tri is the output of the delaunay function.
- x, y, z
- Coordinates of the vertices.
- cdata
- Color data for each vertex or triangle. cdata can be:
- a vector that contains a scalar value for each vertex
- a vector that contains a scalar value for each triangle
- an Mx3 matrix that contains an rgb color for each triangle
- property
- Properties that control the appearance or behavior of the graphics object.
- value
- Value of the properties.
- hAxes
- Axis handle.
Outputs
- h
- Handle of the trimesh graphics object.
Examples
Simple trimesh example:
[x, y] = meshgrid([0:0.2:2]);
z = sin(x)'*cos(y);
tri = delaunay (x(:), y(:));
figure;
h = trimesh(tri, x, y, z);
Set trimesh edgecolor:
[x, y] = meshgrid([0:0.4:2*pi]);
z=sin(x')*cos(x);
tri = delaunay (x(:), y(:));
figure;
h = trimesh(tri, x, y, z);
set(h,'edgecolor','r')
Set cdata per vertex:
[x, y] = meshgrid([0:0.2:2]);
z = sin(x)'*cos(y);
tri = delaunay (x(:), y(:));
figure;
% cdata is a scalar per vertex
cdata = x(:);
h = trimesh(tri, x, y, z, cdata);
figure;
h = trimesh(tri, x, y, z, cdata);
% the edge color is interpolated
set(h, 'edgecolor','interp');
Set cdata per triangle:
[x, y] = meshgrid([0:0.5:2]);
z = cos(y)'*sin(x);
tri = delaunay (x(:), y(:));
figure;
% cdata is a scalar per triangle
cdata = 1:size(tri)(1);
h = trimesh(tri, x, y, z, cdata);
colormap(jet(12))
colorbar;
figure;
% cdata is an rgb color per triangle
cdata = plasma(size(tri)(1));
h = trimesh(tri, x, y, z, cdata);
Comments
If there are no axes, they will be created first.
If z is omitted, a triplot will be created instead.