Menger sponge diagonal cut

12 ビュー (過去 30 日間)
Vojtech Zahradník
Vojtech Zahradník 2019 年 11 月 21 日
編集済み: Vojtech Zahradník 2019 年 11 月 21 日
Hi,
I have little bit problem with fractal. It is about Menger sponge. I need cut it with plane (plane can be diagonal) and split sponge to left side and right side. Is there any way to perform? I want cubes with smooth edges at the cut.
Here is image of my graph and code
.
function menger(n)
if nargin < 1
n = 2;
end
M = 0;
for k=1:n
A = zeros([3^k, 3^k, 3^k]);
A(:,:,1:3^(k-1)) = [M, M, M;
M, ones(size(M)), M;
M, M, M];
A(:,:,3^(k-1)+1:2*3^(k-1)) = ...
[M, ones(size(M)), M;
ones(size(M)), ones(size(M)), ones(size(M));
M, ones(size(M)), M];
A(:,:,2*3^(k-1)+1:3^k) = [M, M, M;
M, ones(size(M)), M;
M, M, M];
M=A;
end
hold on;
axis equal;
d = 1;
for i = 1:3^n
for j = 1:3^n
for k = 1:3^n
if M(i,j,k) == 0
cube(i,j,k,d,n)
end
end
end
end
view(3);
xlabel("X"),ylabel("Y"),zlabel("Z");
hold off;

回答 (0 件)

カテゴリ

Help Center および File ExchangeFractals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by