Make faces of cube transparent

조회 수: 7 (최근 30일)
monkey_matlab
monkey_matlab 2017년 9월 22일
댓글: Ayush singhal 2021년 4월 26일
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
Jan 2017년 9월 22일
patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',hsv(6),'FaceColor','flat', ...
'FaceAlpha', 0.5); % <== Add this
  댓글 수: 3
Steven Lord
Steven Lord 2021년 4월 23일
Draw a cube.
Go around one of the square faces and label the corners 1, 2, 6, and 5 in that order.
Find the other square face that has the line between 2 and 6 as one of its edges.
Label the corner of that square next to 2 with a 3 and the one next to the 6 with a 7.
This gives you the [2 3 7 6] face.
Find the square face that has points labeled 1, 2, and 3. Label the remaining corner 4.
This gives you the [1 2 3 4] face.
Continue until all the points have been labeled. For this simple shape there's only one point left, the 8.
Each face will consist of the points representing one of the rows in the fac variable and the edges between those points.
Ayush singhal
Ayush singhal 2021년 4월 26일
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)
axis padded
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')
%theta in radian
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?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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