how to make color and lighting continuouse using patch

9 ビュー (過去 30 日間)
Itzik Ben Shabat
Itzik Ben Shabat 2013 年 12 月 1 日
回答済み: Meg Noah 2025 年 8 月 5 日
Hi, im trying to visualize 3d objects in MATLAB. when i used the following script i wrote
clear all;
close all
clc
vertices=[0 0 0; 1 0 0; 1 1 0 ;0 1 0; 0 0 1; 1 0 1; 1 1 1; 0 1 1];
faces=[1 2 6 5; 2 3 7 6; 3 4 8 7;4 1 5 8; 1 2 3 4;5 6 7 8];
FV.vertices = [vertices;vertices+[ones(8,1) zeros(8,2)]];
FV.faces = [ faces ; faces+8*ones(6,4)];
FV.FaceVertexCData=0.5*ones(size(FV.vertices,1),3);
figure;
patch_handle=patch('Vertices',FV.vertices,'faces',FV.faces,'FaceVertexCData',FV.FaceVertexCData,'facecolor','interp','facelighting','phong',...
'edgecolor','none','edgelighting','phong');
set(patch_handle,'AmbientStrength',0.8,'DiffuseStrength',0.5,'SpecularStrength',0.5);%,'FaceAlpha',0.5);
light('Position',[1 1 1]);
view(45 ,45);
axis equal
i get that the lighting is not continuous (instead of one continuouse cuboidi can see 2 separate cubs. how do i avoid this ? In the writing of this code i used the following help docs Multiple Patches Specifyingpatch clor thank you

回答 (1 件)

Meg Noah
Meg Noah 2025 年 8 月 5 日
Try this:
clear all;
close all
clc
vertices=[0 0 0; 1 0 0; 1 1 0 ;0 1 0; 0 0 1; 1 0 1; 1 1 1; 0 1 1];
faces=[1 2 6 5; 2 3 7 6; 3 4 8 7;4 1 5 8; 1 2 3 4;5 6 7 8];
FV.vertices = [vertices;vertices+[ones(8,1) zeros(8,2)]];
FV.faces = [ faces ; faces+8*ones(6,4)];
FV.FaceCData=0.5*ones(size(FV.faces,1),3);
figure();
shading interp
grey = [0.5 0.5 0.5];
s = trisurf(FV.faces,FV.vertices(:,1),FV.vertices(:,2),FV.vertices(:,3), ...
'Facecolor',grey,'FaceAlpha',1,'EdgeColor','none');
material(s, 'dull');
axis equal
colormap(gray);
s.EdgeColor = 'none';
s.FaceLighting = 'gouraud';
s.SpecularStrength = 0.01;
s.SpecularExponent = 1;
s.DiffuseStrength = 0.8;
s.AmbientStrength = 0.3;
s.BackFaceLighting = 'lit';
for ilight = 0:60:359
lightangle( 0, ilight)
end
axis equal

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by