Azzera filtri
Azzera filtri

how to draw a cube with planes

27 visualizzazioni (ultimi 30 giorni)
俊鹏 陈
俊鹏 陈 il 9 Set 2022
Commentato: Star Strider il 13 Set 2022
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 Commenti
Rik
Rik il 9 Set 2022
What is your issue with using patch? It provides a 3D syntax as well.
俊鹏 陈
俊鹏 陈 il 13 Set 2022
In fact, I did not find a good patch 3d syntax , so I came here to ask for help, hh :)

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 9 Set 2022
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 Commenti
俊鹏 陈
俊鹏 陈 il 13 Set 2022
Thank you!
Your answer brings me a lot of inspiration, I will try your method!
Best wish to you!
Star Strider
Star Strider il 13 Set 2022
As always, my pleasure!
And to you, too!

Accedi per commentare.

Più risposte (0)

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by