I got a set of points, shaped like a figure 8 filled in (See figure 1)
Now when I use the function "Alphashape" as in:
N=1;
Point=1;
Q=15;
r=20;
[X,Y,Z] = sphere(Q);
count=length(X);
M=zeros(((Q+1)^2),3);
for N=1:(count)
M(((N-1)*count)+1:N*count,1)=r*X(N,:);
M(((N-1)*count)+1:N*count,2)=r*Y(N,:);
M(((N-1)*count)+1:N*count,3)=r*Z(N,:);
N=N+1;
end
count=sqrt(length(M));
count2=length(M);
seen=nan(count2,3);
for TT=1:count^2
Point=M(TT,:)';
if Point(3)>(-sqrt(r^2-((2.7*r)/3.5)^2))
twohalves(TT,:)=Point(1:3)';
end
if Point(3)<(-sqrt(r^2-((2.7*r)/3.5)^2))
twohalves(TT,:)=Point(1:3)'-[0 (0.8*((2*r)-(r-((2.5*r)/3.5)))) 0];
end
end
P=twohalves(:,1:2);
[~, I, ~] = unique(P,'first','rows');
I = sort(I);
P = P(I,:);
twohalves=P;
dt = alphaShape(twohalves(:,1:2),(r/4));
[tri,GG] = alphaTriangulation(dt)
[t,QQ] = tsearchn(P,tri,[0,0])
triplot(tri,GG(:,1),GG(:,2),'r')
This code gives this plot.
Which is nice.
However, the code for "selecting" the nearest triangle in the set does not seem to work.
the code for looking for the point is
[t,QQ] = tsearchn(P,tri,[0,0])
hold on
triplot(tri(t,:),GG(:,1),GG(:,2))
Which clearly is not the triangle closest to the point 0,0.
I allready "solved" that problem using delaunay conversion, and using the pointLocation function.
dt=delaunayTriangulation(twohalves(:,1:2))
triplot(dt)
random_x=0
random_y=0
triangleId=pointLocation(dt, random_x,random_y)
tri = dt(triangleId, [1:end 1]);
patch(P(tri,1), P(tri,2), 'r', 'LineWidth',1, 'FaceColor','r')
but plotting the delaunay transformation of the pointset dt gives THIS:
Which is not the correct shape ( I want the triangulation to follow the "vacuum sealed" constraints that the alpha shape does so very nicely)
So what I'm asking for is:
- A solution to find the right points in the alphashape
or:
- A way to constrain the delaunay so that the shape is "vacuum sealed"
Thanks in advance, and sorry for the long read!