Faces of a Cube - Multifaceted Patches Documentation

11 vues (au cours des 30 derniers jours)
Hans123
Hans123 le 17 Juin 2020
Commenté : Steven Lord le 18 Juin 2020
Hi,
I was reading the literature on MathWorks Documentation regarding Multifaceted Patches and I am not able to understand how the face matrix was evaluated using the vertex matrix. Below I have attached the visaualization used in the Documentations to explain how the matrix is set up, I would apprecaite any pointers to break this down, thanks.
This is to answer the question I have for plotting 3D cubes using patches

Réponse acceptée

Steven Lord
Steven Lord le 18 Juin 2020
Modifié(e) : Steven Lord le 18 Juin 2020
Let's start out by labeling the points whose coordinates are given in the Vertices array.
v = [0 0 0; 1 0 0; 1 1 0; 0 1 0; 0 0 1; 1 0 1; 1 1 1; 0 1 1];
text(v(:, 1), v(:, 2), v(:, 3), string(1:8))
Since the points are in 3-dimensional space let's view the axes with a 3-D view.
view(3)
Now let's show just one of the faces.
hold on
face1 = [1 2 6 5];
P1 = patch(v(face1, 1), v(face1, 2), v(face1, 3), 'r');
The face1 vector indicates that this face is made up of points 1, 2, 6, and 5 in that order. [Connecting them in order [1 2 5 6] would make a different shape.] So the red patch has as its vertices points 1, 2, 6, and 5. Let's draw another face, but this time not a rectangle.
face2 = [8 7 5];
P2 = patch(v(face2, 1), v(face2, 2), v(face2, 3), 'c');
The cyan triangle has as its vertices points 8, 7, and 5.
Now look at the XData, YData, and ZData properties of the patch P1. Compare with the first columns of the x-coordinates, y-coordinates, and z-coordinates matrices shown in the documentation. Those are just the coordinates of the vertices 1, 2, 6, and 5. You could build a similar matrix (though with three rows, not four, since it only has three vertices) using the triangular patch P2 if you wanted to practice your understanding.
  2 commentaires
Hans123
Hans123 le 18 Juin 2020
I am unable to run the text command, but I can visualize your answer. Thanks!
Steven Lord
Steven Lord le 18 Juin 2020
If you can't run that text call because the release of MATLAB you're using predates string, use this instead:
text(v(:, 1), v(:, 2), v(:, 3), {'1', '2', '3', '4', '5', '6', '7', '8'})

Connectez-vous pour commenter.

Plus de réponses (1)

darova
darova le 18 Juin 2020
pretty clear for me
clc,clear
cla
x = [0 1 1];
y = [0 0 1];
patch(x,y,'r')
x = [x+2; 1 2 1.5]; % add second row
y = [y+2; 1 1 2];
patch(x',y','g') % plot data (read by columns)
legend('patch1: 1 face','patch2: 2 faces')

Community Treasure Hunt

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

Start Hunting!

Translated by