
How can I plot overlapping rectangles so that they interact with each other?
6 ビュー (過去 30 日間)
古いコメントを表示
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.

0 件のコメント
採用された回答
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 件のコメント
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 Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


