• Remix
  • Share
  • New Entry

on 17 Oct 2022
  • 9
  • 14
  • 0
  • 0
  • 275
% 3D Extruded Shamrock
%T=linspace(0,2*pi,300);
T=0:.021:2*pi;
% Unit Wave function
g=@(f)(1-(abs(1-mod(T*3,2*pi)/pi)-.3).^2*2).*f(T);
% Convert into a polyshape, and then into a 3d object
t=@triangulation;
T=t(polyshape(g(@cos),g(@sin)));
P=T.Points;
F=T.ConnectivityList;
E=T.freeBoundary;
L=300;% size(P,1)
%R=1:size(E,1);
% The points used in the 3d triangulation are just the og points
% repeating, but at different Z levels. Use trick to fill in Z
% with 0 with no code at same time we fill half the Zs with 2.
j=[P
P];
j(1:L,3)=.3;% How tall to make the extrusion
% Use fcn handles to shorten edge magic.
% The wierd carriage returns/transpose trick saves 1 char per 3
% element array.
e=@(l,m)E(1:L,[l
1
2])+[0
m
L]';
% This is what the fcn handle replaces.
% E(R,[2 1 2])+[0 0 L];
% E(R,[1 1 2])+[0 L L]]
% Generate the final polygon as a triangulation.
V=t([F
F+L
e(2,0)
e(1,L)],j);
% Draw the 3d triangulation
trisurf(V);% ,-hypot(j(:,1),j(:,2))); % Using radial colors makes it
% look cool, but too many char.
shading interp
axis off equal
%colormap summer
camlight
Remix Tree