The Menger Sponge, Complement and Associate

A few months ago, I had never heard of Karl Menger or the cube-like fractal that he invented. Now I have this long blog post about the sponge, and an extension that I am calling its "associate".

内容

Complements and associates

在给定水平上的Menger Sponge分形的补充是将其切开以达到该水平的所有材料。我试图计算海绵补充时遇到的海绵助理。

代码首先出现

I firmly believe that carefully written computer code is a means for people to communicate with each other, as well as control machines. Some of the images that I am about to present can be seen elsewhere on the Web, but I am most pleased with the code that produces them, so I will describe it first.

Here is the main routine,海绵。If you have been following this blog, you will have seen以前有些。At the command line,海绵期望只有两个输入参数,一个非负整数指定级别和一个布尔变量,指定Menger Sponge或其补充。海绵呈现出深色的金色,并带有浅色阴影。功能海绵是递归的,递归电话有两个以上的论点。

零级终止递归,并首先处理。零水平的海绵是a solid cube。The level zero complement is empty and we just display the outline of a cube. Ultimately, all the output is produced by function callscube(d,w,c),,,,which displays a dark or light cube with half-widthwcentered atc = [x y z],,,,so nothing but cubes of various sizes in various locations are displayed. Ordinarily the cube is merged with whatever is in the current figure, thus displaying the union of the two sets. ACLA命令清除当前显示轴,从而启动新集合。

If the level is not zero, we reach the nested loops and the recursive calls. The variablesX,,,,yandztake on all possible combinations of-2,,,,0and+2,因此最终的陈述被执行27次。现在关键变量nz发挥作用。这是非齐率的数量[x y z]。向量[0 0 0]has zero nonzeros and is in the center of some small cube. Vectors like[2 0 0]and[0 -2 0]有一个非零,位于那个小立方体的某些面中心。媒介喜欢[2 0 -2]有两个nonzeros处于某些边缘和矢量中间[-2 2 -2]with three nonzeros are at the corners. There are seven[x y z]'s withnz < 2离开20NZ> = 2。这提供了生成下一个级别的Menger Sponge的三位数规则。

type海绵
function sponge(m,s,d,w,c) % sponge(m,s) % m: level, 20^m cubes. % s: sponge, dark gold or complement, light gold. % % Resursive usage: % sponge(m,s,d,w,c) % d: dark or light. % w: half-width. % c: center. if nargin == 2 init_fig(5) sponge(m,s,s,3,[0 0 0]) elseif m == 0 && s cube(d,w,c) elseif m == 0 cube([],w,c) else w = w/3; c = c/3; for x = [-2 0 2] for y = [-2 0 2] for z = [-2 0 2] nz = nnz([x y z]); if s && nz >= 2 sponge(m-1,s,d,w,c+[x y z]) elseif ~s && nz < 2 sponge(m-1,~s,d,w,c+[x y z]) end end end end end end

级别0

这是0级海绵,一个实心立方体。

CLA海绵(0,true)

This is the level 0 complement. It is empty.

CLA海绵(0,false)

1级

Trisect level 0 into 3x3x3 = 27 smaller cubes. Delete the center cube and the center of each face. This is the level 1 sponge with 20 smaller cubes and seven holes.

CLA海绵(1,true)

这是1级补充,七个缺失的立方体。

CLA海绵(1,false)

If you could somehow put the level 1 sponge and the level 1 complement together again, you would recreate a slightly used, but full, cube.

CLA海绵(1,true)海绵(1,false)

1级是as far as I need to golate last year为了装饰我季节的问候

2级

2级海绵有20^2 = 400立方体。我在第二级方面走了很远myfirst postabout the Menger sponge.

CLA海绵(2,正确)

The next figure has never appeared before inCleve's Corner。I call it the level 2partial complement

CLA海绵(2,false)

形成2级部分补体的结合和1级补充,以给出整个级别2的补充。

海绵(1,false)

2级海绵的结合及其补充是一个完整的立方体。

海绵(2,正确)

级别3

The is the level 3 Menger sponge. It is made from20^3 = 8000small cubes. Its volume is less than half that of the original cube.

CLA海绵(3,true)

The is the level 3 partial complement.

CLA海绵(3,false)

Combine levels 1, 2 and 3 partial complements to produce the entire level 3 complement.

海绵(2,false)海绵(1,false)

The union of the level 3 sponge and its complement is, again, full.

海绵(3,true)
formatcompactformatshort

Ten levels

我没有足够的时间,我的笔记本电脑没有足够的记忆力超过3级,但是如果我们可以继续进行分配,那么10级海绵就会由20^10 = 10,240,000,000,000,000very tiny cubes.

Levelm会减少水平的体积0cube by a factorr.^mwhere

r =(20/27)
r = 0.7407

By level 10 the volume of the sponge would be only 5 percent of the original volume, and the remaining 95 percent would be in the complement.

m =(0:10)';卷= [r。^m 1-r。^m];
fprintf('\n\n volume\n') fprintf(' level sponge complement\n') fprintf('%10d%8.3f%8.3F \ n',,,,[m volumes]')
volume level sponge complement 0 1.000 0.000 1 0.741 0.259 2 0.549 0.451 3 0.406 0.594 4 0.301 0.699 5 0.223 0.777 6 0.165 0.835 7 0.122 0.878 8 0.091 0.909 9 0.067 0.933 10 0.050 0.950
plot(m,volumes,'o-',,,,'linewidth',1.0)Xlabel('等级') ylabel('volume') legend({'sponge',,,,'complement'},'position',[。67.47 .21 .08])

联系

A Web dictionary says that anassociate是组织中有限或下属成员资格的人。我们都熟悉学术组织的副教授。当我学习如何计算海绵补充时,我不小心创建了这些海绵同伴。我喜欢这些图像,所以我把它们留在了周围。

我现在对生成的代码是almost the same as the code for generating sponges. Just count the number of zeros in a coordinate vector instead of the number of nonzeros.

dbtype28海绵dbtype28associate
28nz = nnz([x y z]); 28 nz = 3 - nnz([x y z]);

2级

在0和1级别,海绵和伴侣构建相同的对象。但是在2级,我们有这个家伙有49个立方体。

CLAassociate(2,true)

同事有自己的补充。立方体计数m7^m对于同事和20*7^(m-1)因为它的补充。该级别2有149个立方体。

CLAassociate(2,false)

级别3

Here is the level 3 associate.

CLAassociate(3,true)

以及第三级联合补充。

CLA助理(3,false)

4级

最好使用较大的格式查看4级图像。如果您想查看它们,请单击这些链接。

https://blogs.mathworks.com/cleve/files/level_4_true.png

https://blogs.mathworks.com/cleve/files/level_4_false.png




与Matlab®R2021A一起出版

|

Comments

To leave a comment, please clickhereto sign in to your MathWorks Account or create a new one.