Dynamically change FaceVertexCData of a patch
7 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a patchTest() function as follows:
function [mainPatch] = patchTest()
mainColor = [1 0 0];
vert = [0 0 0;1 0 0;1 1 0;0 1 0;0 0 1;1 0 1;1 1 1;0 1 1];
face = [1 2 6;5 2 3;7 6 3;4 8 7;4 1 5;8 1 2;3 4 5;6 7 8];
%Use one color for each face (An RGB triplet)
%True color, one color per face - data format
colorData = zeros(size(face,1), 3);
for i=1:size(colorData,1)
colorData(i,:) = mainColor;
end
figure;
axis ij
axis tight
grid on;
daspect([1,1,1])
rotate3d on;
mainPatch = patch('Faces',face,'Vertices',vert);
mainPatch.FaceAlpha = 1;
mainPatch.EdgeColor = 'b';
mainPatch.FaceColor = 'flat';
mainPatch.FaceVertexCData = colorData;
end
[mainPatch] = patchTest();
As you can see, I assign the patch object to a work space variable called mainPatch. What I want to do next is input this variable in another function and be able to modify the FaceVertexCData property of the patch. This is an example of what I want to achieve:
function [] = recolorTest(mainPatch)
%Recolor patch
newColor = [0 .75 0];
%Rows of the triangular faces which I want to recolor
newCTriangles = reshape([3, 6, 2],3,1)
colorData = mainPatch.FaceVertexCData;
for i=1:size(newCTriangles,1)
colorData(newCTriangles(i,1),:) = newColor;
end
end
I then call the function to recolor the patch
recolorTest(mainPatch);
The problem is that no changes in color appear on the patch figure. I also checked the current FaceVertexCData:
newColorData = mainPatch.FaceVertexCData;
In this variable, no changes in the color of the faces has appeared either. What am I doing wrong?
2 个评论
回答(1 个)
Steven Lord
2018-10-15
What type of values are you using to set the FaceVertexCData property? One color per face, one color per vertex, indexed colors, true colors? Double or single precision, integer data, or logical? If double or single precision, are the values between 0 and 1 or are some of them larger than that?
Can you post a small simple example with which you see no change when you modify the FaceVertexCData property? Say no more than 10-15 data points?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!