Hypotrochoid in 3D
Eric Ludlam on 26 Oct 2021
% 3D version of a hypotrochoid using polyshape & triangulations.
% The API for polyshape and triangulation include a lot of methods
% and properties that are very long. This required a lot of
% crunching to make it fit.
% These are the original constants from the first version of this
% script. I used constant folding and some other tricks to
% eliminate a lot of characters from the code.
%A=.2; B=.7; C=.5; L=7;
%d=linspace(0, L*2*pi, 500);
% X,Y differ only in the trig fcn used, so use an anon fcn handle,
% then inline X,Y into the polyshape call.
% Use polyshape to convert the single 'face' into a set of known
% boundaries we can use in a 3d triangulation.
% L = size(P,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.
% Use fcn handles to shorten edge magic.
% The wierd carriage returns/transpose trick saves 1 char per 3
% element array, or 2 chars when transpose optional.
% This is what the above 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.
% Draw the 3d triangulation
axis off equal
%colormap hsv % Sad - I would have liked this