필터 지우기
필터 지우기

how to draw a cube with planes

조회 수: 27 (최근 30일)
俊鹏 陈
俊鹏 陈 2022년 9월 9일
댓글: Star Strider 2022년 9월 13일
Thank you for your answer!
Actually, I want to draw the cube with the plane property. But there is no good way
here is my data and my method(Draw the cube through the lines.)
coor_Scope = [0.2065,0.5765;
-0.5867,-0.2267;
-0.4419,0.4381];
A=[coor_Scope(1,1),coor_Scope(2,2),coor_Scope(3,2);
coor_Scope(1,1),coor_Scope(2,2),coor_Scope(3,1);
coor_Scope(1,2),coor_Scope(2,2),coor_Scope(3,1);
coor_Scope(1,2),coor_Scope(2,2),coor_Scope(3,2);
coor_Scope(1,1),coor_Scope(2,1),coor_Scope(3,2);
coor_Scope(1,1),coor_Scope(2,1),coor_Scope(3,1);
coor_Scope(1,2),coor_Scope(2,1),coor_Scope(3,1);
coor_Scope(1,2),coor_Scope(2,1),coor_Scope(3,2)];
d=[1 2 3 4 8 5 6 7 3 2 6 5 1 4 8 7];
plot3(A(d,3),A(d,1),A(d,2));
The effect is shown above.
I want the cube to have planar properties, such as color, transparency, etc.
For example, the “patch” function can be modified freely.
That's all my questions. Thank you again for your answers!
  댓글 수: 2
Rik
Rik 2022년 9월 9일
What is your issue with using patch? It provides a 3D syntax as well.
俊鹏 陈
俊鹏 陈 2022년 9월 13일
In fact, I did not find a good patch 3d syntax , so I came here to ask for help, hh :)

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

채택된 답변

Star Strider
Star Strider 2022년 9월 9일
This is generally how to draw the patch plots in 3D.
You organised them well, however they still need a bit of revision to plot the surfaces correctly —
coor_Scope = [ 0.2065, 0.5765;
-0.5867,-0.2267;
-0.4419, 0.4381];
A=[coor_Scope(1,1),coor_Scope(2,2),coor_Scope(3,2);
coor_Scope(1,1),coor_Scope(2,2),coor_Scope(3,1);
coor_Scope(1,2),coor_Scope(2,2),coor_Scope(3,1);
coor_Scope(1,2),coor_Scope(2,2),coor_Scope(3,2);
coor_Scope(1,1),coor_Scope(2,1),coor_Scope(3,2);
coor_Scope(1,1),coor_Scope(2,1),coor_Scope(3,1);
coor_Scope(1,2),coor_Scope(2,1),coor_Scope(3,1);
coor_Scope(1,2),coor_Scope(2,1),coor_Scope(3,2)];
d=[1 2 3 4 8 5 6 7 3 2 6 5 1 4 8 7];
X = A(d,3);
Y = A(d,1);
Z = A(d,2);
figure
plot3(A(d,3),A(d,1),A(d,2));
xlabel('X')
ylabel('Y')
zlabel('Z')
[az,el] = view;
figure
hold on
patch([X(1:6) flip(X(1:6))], [Y(1:6) flip(Y(1:6))], [Z(1:6) flip(Z(1:6))], 'r', 'FaceAlpha',0.25)
kp = 2;
patch([X((1:6)+kp) flip(X((1:6)+kp))], [Y((1:6)+kp) flip(Y((1:6)+kp))], [Z((1:6)+kp) flip(Z((1:6)+kp))], 'g', 'FaceAlpha',0.25)
kp = 10;
patch([X((1:6)+kp) flip(X((1:6)+kp))], [Y((1:6)+kp) flip(Y((1:6)+kp))], [Z((1:6)+kp) flip(Z((1:6)+kp))], 'b', 'FaceAlpha',0.25)
hold off
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
view(az,el)
I leave the rest to you.
The ‘secret’ to the patch function is that each patch has to enclose a specific region in order in every coordinate dimension. In a 2D plot this would be —
figure
patch([1 3 3 1], [1 2 3 4], 'g')
axis([0 4 0 5])
text([1 3 3 1], [1 2 3 4], compose('(%d, %d)', [1 3 3 1; 1 2 3 4].'))
That demonstrates how it works.
.
  댓글 수: 2
俊鹏 陈
俊鹏 陈 2022년 9월 13일
Thank you!
Your answer brings me a lot of inspiration, I will try your method!
Best wish to you!
Star Strider
Star Strider 2022년 9월 13일
As always, my pleasure!
And to you, too!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by