Apply a color variation to a triangular face
1 次查看(过去 30 天)
显示 更早的评论
Hi! I have this code. I would like to color the face of the triangle taking into account the RGB colors present on the three nodes.
node_1 = [-46.924, 11.0584, -59.8431];
node_2 = [-45.9522, 13.4294, -59.5705];
node_3 = [-46.4695, 9.8787, -57.7669];
nodes = [node_1; node_2; node_3];
face = [1,2,3];
figure
plot3(node_1(:,1),node_1(:,2),node_1(:,3),'.','Color',[176/255,255/255,0/255],'Markersize',20)
hold on
plot3(node_2(:,1),node_2(:,2),node_2(:,3),'.','Color',[0/255,255/255,155/255],'Markersize',20)
plot3(node_3(:,1),node_3(:,2),node_3(:,3),'.','Color',[0/255,199/255,255/255],'Markersize',20)
trimesh(face(:,:),nodes(:,1),nodes(:,2),nodes(:,3),'EdgeColor',[210/255, 210/255, 210/255],'Linewidth',1,'Facecolor','w')
hold off
grid off
view([20,130,40])
0 个评论
采纳的回答
Walter Roberson
2023-5-15
编辑:Walter Roberson
2023-5-15
You can then set the patch properties. In particular, look at https://www.mathworks.com/help/matlab/ref/matlab.graphics.primitive.patch-properties.html#buduav0-1-FaceVertexCData FaceVertexCData along with 'FaceColor', 'interp' . Done right you can assign a color to each vertex, and then the face color will be a progressive interpolation between the colors of the vertices.
5 个评论
Walter Roberson
2023-5-16
node_1 = [-46.924, 11.0584, -59.8431];
node_2 = [-45.9522, 13.4294, -59.5705];
node_3 = [-46.4695, 9.8787, -57.7669];
nodes = [node_1; node_2; node_3];
face = [1,2,3];
vertex_colors = [176, 255, 255
0, 255, 155
0, 199, 255]./255;
h = trimesh(face(:,:),nodes(:,1),nodes(:,2),nodes(:,3),'EdgeColor',[210/255, 210/255, 210/255],'Linewidth',1,'Facecolor','w')
h.FaceVertexCData = vertex_colors;
h.FaceColor = 'interp';
view([20,130,40])
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!