MATLAB: Undesired gaps in alphashape

alphashapeMATLAB

I am having trouble to generate a "gap-free" alpha shape for the following example:
% surface points from: https://stackoverflow.com/questions/10655393
aminor = 1.; % Torus minor radius
Rmajor = 3.; % Torus major radius
sd = 24;
theta = linspace(-pi, pi, sd) ; % Poloidal angle
phi = linspace(0., 2.*pi, 2*sd) ; % Toroidal angle
[t, p] = meshgrid(phi, theta);
x = (Rmajor + aminor.*cos(p)) .* cos(t);
y = (Rmajor + aminor.*cos(p)) .* sin(t);
z = aminor.*sin(p);
I am creating the alpha shape with
alpha = 1;
shp = alphaShape(x(:),y(:),z(:), alpha);
plot(shp);
Here is the figure:
As you can see, alpha should be big enough to cover all distances between the desired surface points, yet the returned alpha shape contains some gaps.
What am I missing?
PS: I get identical results on Matlab R2016b and R2017b.

Best Answer

The criticalAlpha method computes that you should use an alpha slightly greater than 1 to get all the points in 'one-region'. Giving it a bit extra leeway, I chose to use 1.03:
alpha = 1.03;
shp = alphaShape(x(:), y(:), z(:), alpha);
crit = criticalAlpha(shp, 'one-region')
plot(shp)