Apply a color variation to a triangular face

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])

 採用された回答

Walter Roberson
Walter Roberson 2023 年 5 月 15 日
編集済み: Walter Roberson 2023 年 5 月 15 日

0 投票

Assign the result of trimesh() to a variable. The result will be a patch object.
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 件のコメント

Alberto Acri
Alberto Acri 2023 年 5 月 16 日
Thank you for your reply. Is there any code available to do this? Or do you know how it could be done?
Walter Roberson
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 = [1 0 0;
0 1 0;
0 0 1];
h = trimesh(face(:,:),nodes(:,1),nodes(:,2),nodes(:,3),'EdgeColor',[210/255, 210/255, 210/255],'Linewidth',1,'Facecolor','w')
h =
Patch with properties: FaceColor: [1 1 1] FaceAlpha: 1 EdgeColor: [0.8235 0.8235 0.8235] LineStyle: '-' Faces: [1 2 3] Vertices: [3×3 double] Show all properties
h.FaceVertexCData = vertex_colors;
h.FaceColor = 'interp';
view([20,130,40])
Alberto Acri
Alberto Acri 2023 年 5 月 16 日
Thank you for your reply. But I wanted to start with the colors present in the vertices that are mixed in the center of the triangle.
The colors are:
for node 1: [176/255,255/255,0/255]
For node 2: [0/255,255/255,155/255]
for node 3: [0/255,199/255,255/255]
Walter Roberson
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 =
Patch with properties: FaceColor: [1 1 1] FaceAlpha: 1 EdgeColor: [0.8235 0.8235 0.8235] LineStyle: '-' Faces: [1 2 3] Vertices: [3×3 double] Show all properties
h.FaceVertexCData = vertex_colors;
h.FaceColor = 'interp';
view([20,130,40])
Alberto Acri
Alberto Acri 2023 年 5 月 16 日
perfect!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeVector Fields についてさらに検索

製品

リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by