patch
Creates 2D or 3D patches in an axis.
Syntax
h = patch(x, y, c)
h = patch(x, y, z, c)
h = patch('vertices', vertices_matrix, 'faces', faces_matrix)
h = patch(hAxes, ...)
Inputs
- x, y, z
- Coordinates of patch vertices.
- c
- Patch color.
- vertices_matrix
- An Mx2 or Mx3 matrix that contains the coordinates of the patch vertices. M is the number of vertices.
- faces_matrix
- An MxN matrix that contains the indices of the vertices of each patch. M is the number of patches and N is the number of vertices of each patch. NaN may be used if not all polygons have the same number of vertices (see the Examples section).
- hAxes
- Axis handle.
Outputs
- h
- Handle of the patch graphics object.
Examples
clf;
t1 = (1/16:1/8:1) * 2*pi;
t2 = ((1/16:1/8:1) + 1/32) * 2*pi;
x = tan (t1) - 0.8;
y = sin (t1);
h = patch (x',y','r')
x = [0 0.25 0.5 1 1 0.5 0.25 0 -0.5 -0.5]';
y = [0 0 0 0.5 1 1.5 1.5 1.5 1 0.5]';
verts = [x, y];
figure(1);
% Create one patch which constinst of 10 vertices
faces = [1:10];
h = patch('vertices',verts,'faces',faces);
figure(2);
% Create two patches each one consisting of 4 vertices
faces = [3 4 5 6; 8 9 10 1];
h = patch('vertices',verts,'faces',faces);
figure(3);
% Create two patches, the first patch consists of 6 vertices,
% the second patch consists of 4 vertices
faces = [2 3 4 5 6 7; 8 9 10 1 NaN NaN];
h = patch('vertices',verts,'faces',faces);
clf;
x = [0 1 1 0; 1 1 0 0; 0.5 0.5 0.5 0.5];
y = [0 0 1 1; 0 1 1 0; 0.5 0.5 0.5 0.5];
z = [0 0 0 0; 0 0 0 0; 1 1 1 1];
h = patch(x,y,z,'r');
clf;
x = [0 1 1 0; 1 1 0 0; 1 1 0 0; 0 1 1 0];
y = [0 0 1 1; 0 1 1 0; 0 1 1 0; 0 0 1 1];
z = [0 0 0 0; 0 0 0 0; 1 1 1 1; 1 1 1 1];
h = patch(x,y,z,'r');
clf;
x = [0.5 0; 1.5 0; 2 0; 1.5, 0; 0.5 0; 0 0];
y = [0 0; 0 0.5; 0 1; 0 1.5; 0 1; 0 0.5];
z = [0 0.5; 0 0; 0.5 0; 1 0.5; 1 1; 0.5 1];
h = patch(x,y,z,'r');
clf;
verts = [0 2.5 0; 1 1.5 0; 1.5 1 0; 2 0.5 0; 2.5 0, 0.5; 2 0.5 1;
1.5, 1 1; 1 1.5 0.5; 1 1.5 1; 0 2.5 1; 0.5 2 0.5];
faces = [1 2 11 NaN NaN NaN; 9 10 11 NaN NaN NaN; 3 4 5 6 7 8];
h = patch('vertices',verts,'faces',faces);
Comments
If there are no axes, they will be created first.