how to make color and lighting continuouse using patch

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by