Menger sponge diagonal cut

조회 수: 14 (최근 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 CenterFile Exchange에서 Fractals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by