Faces of a Cube - Multifaceted Patches Documentation

11 次查看(过去 30 天)
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

采纳的回答

Steven Lord
Steven Lord 2020-6-18
编辑:Steven Lord 2020-6-18
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 个评论
Hans123
Hans123 2020-6-18
I am unable to run the text command, but I can visualize your answer. Thanks!
Steven Lord
Steven Lord 2020-6-18
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'})

请先登录,再进行评论。

更多回答(1 个)

darova
darova 2020-6-18
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')

类别

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