フィルターのクリア

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 Center および File ExchangePolygons についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by