Menger sponge diagonal cut
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Fractals dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!