How to plot a 3D cube based if i have the coordinates of the 8 surrounding nodes?
조회 수: 571 (최근 30일)
표시 이전 댓글
Hello community,
I want to plot a 3d cube based on the coordinates of my geometry (8 nodes). The coordinates of my cube are:
coord=[0 0 0;
0.5 0 0;
0.5 0.5 0;
0 0.5 0;
0 0 0.5;
0.5 0 0.5;
0.5 0.5 0.5;
0 0.5 0.5;];
Thanks a lot in advance.
댓글 수: 0
채택된 답변
Kelly Kearney
2021년 11월 4일
To expand on Star Strider's answer, in your example, you've specified a list of coordinates, but you haven't told Matlab how they should be connected. Based on your original example, the following array of row indices defines the faces of your cube:
coord = [...
0 0 0;
0.5 0 0;
0.5 0.5 0;
0 0.5 0;
0 0 0.5;
0.5 0 0.5;
0.5 0.5 0.5;
0 0.5 0.5;];
idx = [4 8 5 1 4; 1 5 6 2 1; 2 6 7 3 2; 3 7 8 4 3; 5 8 7 6 5; 1 4 3 2 1]';
To plot, substitute the coordinates:
xc = coord(:,1);
yc = coord(:,2);
zc = coord(:,3);
ax(1) = subplot(2,1,1);
patch(xc(idx), yc(idx), zc(idx), 'r', 'facealpha', 0.1);
view(3);
% Deformed
coord2 = coord + rand(size(coord))*0.1;
xc = coord2(:,1);
yc = coord2(:,2);
zc = coord2(:,3);
ax(2) = subplot(2,1,2);
patch(xc(idx), yc(idx), zc(idx), 'r', 'facealpha', 0.1);
view(3);
댓글 수: 7
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Elementary Polygons에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!