Menger sponge diagonal cut

1 view (last 30 days)
Vojtech Zahradník
Vojtech Zahradník on 21 Nov 2019
Edited: Vojtech Zahradník on 21 Nov 2019
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;

Answers (0)

Categories

Find more on Fractals in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!