How can I plot overlapping rectangles so that they interact with each other?

조회 수: 3 (최근 30일)
kornkob
kornkob 2023년 5월 16일
댓글: DGM 2023년 5월 17일
If I wanted to have rectangles visualised in a 3D space with a small and constant depth that overlapped each other in a certain pattern (similar to a weaving pattern), how would I go about it?
I was thinking of using patch() for the rectangles themselves but I couldn't figure out how to get further than that. I'm looking for something similar to the sketch below.

채택된 답변

DGM
DGM 2023년 5월 16일
편집: DGM 2023년 5월 17일
Here's a start.
w = 4; % ribbon width
th = 0.2; % ribbon thickness
m = 0; % in-plane distance between bend interior and ribbon edge
mz = 0.1; % spacing between wide faces and z=0 plane
s = 2; % nominal spacing between ribbon edges
tl = 3; % tail length
p = th*tan(atan((2*mz + th)/s)/2); % a little bit of math
% vertices [x y z]
V0 = [-tl 0 mz;
w+m 0 mz;
w+m+s 0 -mz-th;
2*(w+m)+tl+s+p 0 -mz-th;
2*(w+m)+tl+s+p w -mz-th;
w+m+s w -mz-th;
w+m w mz;
-tl w mz;
-tl 0 mz+th;
w+m+p 0 mz+th;
w+m+p+s 0 -mz;
2*(w+m)+tl+s+p 0 -mz;
2*(w+m)+tl+s+p w -mz;
w+m+p+s w -mz;
w+m+p w mz+th;
-tl w mz+th];
% each row is the list of vertices defining a quadrilateral patch
F = [1 2 7 8; 2 3 6 7; 3 4 5 6; 9 10 15 16; 10 11 14 15; 11 12 13 14; 1 8 16 9;
4 5 13 12; 1 9 10 2; 10 2 3 11; 3 11 12 4; 5 13 14 6; 14 6 7 15; 7 15 16 8];
% each ribbon can be built using simple transformations of V
patch('faces',F,'vertices',V0,'facecolor','r')
V = V0(:,[2 1 3]); % swap x,y
V(:,3) = -V(:,3); % flip z
patch('faces',F,'vertices',V,'facecolor','g')
V = V0;
V(:,2) = V(:,2) + s + 2*m + w + p; % offset y
V(:,3) = -V(:,3); % flip z
patch('faces',F,'vertices',V,'facecolor','b')
V = V0(:,[2 1 3]); % swap x,y
V(:,1) = V(:,1) + s + 2*m + w + p; % offset x
patch('faces',F,'vertices',V,'facecolor','y')
% arrange the view
view(3)
axis equal
The transformations could also be done using copyobj() and hgtransform(), but I think this is just easier.
If you can read my tablet-writing, this diagram should explain the parameters and the math.
  댓글 수: 7
kornkob
kornkob 2023년 5월 17일
This is super helpful, thank you so much!
DGM
DGM 2023년 5월 17일
I fixed a mistake in the calculation of P. I'm pretty sure I had that right before I split m into two parameters, but I had to make mistakes somewhere.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by