• Remix
  • Share
  • New Entry

  • Tim

  • /
  • Reassembly

on 20 Nov 2023
  • 22
  • 38
  • 0
  • 2
  • 1213
drawframe(1);
Write your drawframe function below
function drawframe(f)
% Remix / putting back together.
persistent V T TU ginds Xo R C kf
% Scale factor
SF=[linspace(4.075, 0.2, 18), -sin(linspace(0, 2*pi,48-18)).*exp(-linspace(0, 2,48-18))];
rng default
N=150; % Number of voronoi domains
v=@(x)vecnorm(x); % This is used a lot...
if f==1
% Distribute points in the unit sphere, biased toward the center
Xo=randn(3,N);
Xo=Xo./v(Xo).*rand(1, N);
% Bounding layer of points that will create our outer surface. Need
% lots of them...
NA=100;
ps=randn(3,NA);
ps=1.3*ps./v(ps);
% Concatenate
X=[Xo,ps]';
% Voronoi diagram
[V,R]=voronoin(X);
mnR=cellfun(@min, R)~=1; % Which cells have inf's
ginds=unique(cell2mat(R(~mnR)')); % Get bordering nodes
Iinds=setdiff(1:size(V,1), ginds); % Get interior nodes
mxr=max(v(V(Iinds,:)'));
ginds(1)=[]; % Get rid of inf
C=[1,1,1];
% Make non-inf outer-nodes have unit radius * some small scale factor
V(ginds,:)=1.3*V(ginds,:)./v(V(ginds,:)')';
kf = convhull(V(ginds,1),V(ginds,2),V(ginds,3));
TS=@(k,x,y,z,C)trisurf(k,x,y,z,'FaceC',C,'EdgeC','none');
cnt = 1;
TU=TS(kf,V(ginds,1),V(ginds,2),V(ginds,3),C/2);
material(TU,[0,1,0,3]);
TU.Visible='off';
hold on;
for n = 1:length(mnR)
if mnR(n) == 1
xt=V(R{n},1);
yt=V(R{n},2);
zt=V(R{n},3);
xt=xt+SF(f)*Xo(1,n);
yt=yt+SF(f)*Xo(2,n);
zt=zt+SF(f)*Xo(3,n);
k = convhull(xt,yt,zt);
T{n}=TS(k,xt,yt,zt,C/2);
material(T{n},[0,1,0,3]);
if cnt == 1
set(gca, 'color', 'k');
axis equal off
axis([-1,1,-1,1,-1,1]*6);
cnt = cnt + 1;
camproj p
camva(70);
campos([-55-5 -71 52]/30);
set(gcf,'color','k');
light;
light;
end
end
end
else
if SF(f) < 0
1;
end
% Loop over fragments and expand
if SF(f) > 0
TU.Visible = 'off';
for n = 1:N
T{n}.Visible = 'on';
T{n}.Vertices=V(R{n},:)+SF(f)*Xo(:,n)';
end
else
TU.Visible = 'on';
TU.Vertices = V(ginds,:)*(1+SF(f));
for n = 1:N
T{n}.Visible = 'off';
end
end
end
%S.D.G.
end
Animation
Remix Tree