MATLAB Answers

0

Menger sponge diagonal cut

Asked by Vojtech Zahradník on 21 Nov 2019 at 19:39
Latest activity Edited by Vojtech Zahradník on 21 Nov 2019 at 19:42
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 Comments

Sign in to comment.

0 Answers