• Remix
  • Share
  • New Entry

on 22 Nov 2023
  • 8
  • 3
  • 0
  • 0
  • 1283
drawframe(1);
Write your drawframe function below
function drawframe(f1)
% create Tetrahedron
v=[[-1,0,0];[1,0,0];[0,sqrt(3),0];[0,sqrt(3)/3,2*sqrt(6)/3]];
f=[[1,3,2];[1,2,4];[2,3,4];[3,1,4]];
plus_minus=1;
index=round(linspace(1,5.45,48));
i=index(f1);
TR_out=Fractal_Kochsnow3D_tri(triangulation(f,v),0.5,i,plus_minus);
c=jet(size(TR_out.Points,1));
% trisurf(TR_out,'FaceColor','blue')
patch('Faces',TR_out.ConnectivityList,'Vertices',TR_out.Points,'FaceVertexCData',c,'EdgeColor','k','FaceColor','interp','LineWidth',0.1);
axis equal off;
view(30+f1,30+1.2*f1);
function TR_out = Fractal_Kochsnow3D_tri(TR,m,n,plus_minus,varargin)
%% 缺省值处理。。 默认为向外扩展,可选为向内或者向外
if isempty(varargin)
inorout = 'out';
else
inorout = varargin{1};
end
%% 循环获取结果
%inorout1={'out';'in'};
for i = 1:n
P=[];
T=[];
for j = 1:size(TR.ConnectivityList,1)
TR1 = triangulation([1,2,3],TR.Points(TR.ConnectivityList(j,:),:));
Temp = KochSeed(TR1,m,plus_minus,inorout);
if j==1
P=[P;Temp.Points];
T=[T;Temp.ConnectivityList];
else
T=[T;Temp.ConnectivityList+size(P,1)];
P=[P;Temp.Points];
end
end
TR_out = triangulation(T,P);
TR=TR_out;
end
end
end
function TR_out=KochSeed(TR,m,plus_minus,varargin)
%% 缺省值处理。。 默认为向外扩展,可选为向内或者向外
if isempty(varargin)
inorout = 'out';
else
inorout = varargin{1};
end
% if strcmpi(inorout,'in')
% inorout = 1;
% else
% inorout = -1;
% end
%% 处理不同的inorout
if strcmpi(inorout,'in')
v=TR.Points([1,3,2],:);
TR = triangulation(TR.ConnectivityList,v);
end
%正三角形的边长dl
dl=norm(TR.Points(1,:)-TR.Points(2,:));
%以dl/2构建正四面体,那么它的高h
h=dl/2*sqrt(6)/3*m;
v=[TR.Points;[TR.Points+TR.Points([2,3,1],:)]/2;TR.incenter+plus_minus*TR.faceNormal*h];
f=[[1,4,6;2,5,4;3,6,5];[4,5,7;5,6,7;6,4,7]];
TR_out=triangulation(f,v);
end
Animation
Remix Tree