• Remix
  • Share
  • New Entry

on 31 Oct 2021
  • 3
  • 52
  • 0
  • 0
  • 280
% Spirograph as Pointillist Art
set(gcf,Color="#151")
% Spirograph
d=(0:.001:1)*pi*18;
% X,Y differ only in the trig fcn used, so use an anon fcn handle,
% then inline X,Y into the polyshape call.
g=@(h)7*h(d)-h(d*2/9)*7;
% Use polyshape to convert the single 'face' into a set of known
% boundaries we can use in a 3d triangulation.
ps=polyshape(g(@cos),g(@sin));
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
% Random Scatter Pts
d=@()rand(5e4,1)*34-17;
x=d();
y=d();
% og 'inpolygon' didn't like this polygon for some reason, but polyshape
% and this method worked better.
[in,on]=isinterior(ps,x,y);
hold on
c=@(m)hypot(x(m),y(m)); % Add groovy colors
scatter(x(~in),y(~in),20,-c(~in),'.')
scatter(x(in),y(in),20,c(in),'.')
colormap hsv
axis off equal tight
Remix Tree