I have to drew sierpinski tetrahedron but the final figure is a 2D plane in 3D
    4 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
 I had been asked to drew sierpinski tetrahedron i know i need X,Y,Z not only X,Y so i added the Z to the original code but it is giving me the sierpinski triangle in 3D space .. what changes i have to do ??
%code
%if true
  % code
%  end
N=1000;
%fix points of the algorithm: the vertices of the triangle
Ax = [0 0 0 ; 1 1 -1 ; 1 -1 -1 ];
Ay = [0 0 0 ; 5 5 5 ; 5 5 5 ]; 
Az = [0 0 0 ; 1 1 -1 ; -1 1 1 ];
if true
  % code
end
figure;
title('Sierpinski triangle');
xlim([0 N])
ylim([0 N])
zlim([0 N])
iternum=1000; %iteration number
C=zeros(iternum,3); %points of the triangle
c= [Ax(randi([1,3])),Ay(randi([1,3])),Az(randi([1,3]))]%choose a fix point randomly hold on; % c - actual point - the reference (one of the fix points at first)
 % if true
    % code
%  end
for i=2:iternum
    r =randi([1,3]) ; %choose a fix point randomly
    c = [(c(1,1)+Ax(r,1))/2,(c(1,2)+Ay(r,2))/2,(c(1,3)+Az(r,3))/2]; %the midpoint of the new point - fix ine
    C(i,:,:)=c; %store the new point 
    %plot step by step:
     plot3(c(:,1), c(:,2),c(:,3), '.', 'MarkerSize', 1);
   title('Sierpinski triangle');
   xlabel(['Iteration: ', num2str(i)]);
   drawnow;
end
 plot3(C(:,1), C(:,2),C(:,3), '.', 'MarkerSize', 1);
 title('Sierpinski triangle');
 xlabel(['Iteration: ', num2str(iternum)]);
0 Kommentare
Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
