Make faces of cube transparent

19 views (last 30 days)
monkey_matlab on 22 Sep 2017
Commented: Ayush singhal on 26 Apr 2021
Hello,
I have made a 3D cube but would like to have the faces appear transparent. How do I go about doing that? Thanks.
Here is my code:
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];
fac = [1 2 6 5;2 3 7 6;3 4 8 7;4 1 5 8;1 2 3 4;5 6 7 8];
patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',hsv(6),'FaceColor','flat')
view(3)
axis vis3d
rotate3d
xlabel('x')
ylabel('y')
zlabel('z')

Jan on 22 Sep 2017
patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',hsv(6),'FaceColor','flat', ...
'FaceAlpha', 0.5); % <== Add this
Ayush singhal on 26 Apr 2021
Thanks I got it.
I have one more question.
[x y] = meshgrid(-6:1:6); % Generate x and y data
z = zeros(size(x,2)); % Generate z data
surf(x, y,z) % Plot the surface
view(2)
hold on
vert = [0 0 0;3 0 0;3 3 0;0 3 0;0 0 3;3 0 3;3 3 3;0 3 3];
fac = [1 2 6 5;2 3 7 6;3 4 8 7;4 1 5 8;1 2 3 4;5 6 7 8];
patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',hsv(6),'FaceColor','flat', ...
'FaceAlpha', 0);
view(3)
axis vis3d
rotate3d
xlabel('x')
ylabel('y')
zlabel('z')
In the above code, I have put the cube on image plane but how to centred the cube on the plane. Is it due to the lower face of cube of else?
could you modify it or give me some insight?

Categories

Find more on Lighting, Transparency, and Shading in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!