Problem with contraining a general delaunay Triangulation

2 次查看(过去 30 天)
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:
%%Generate sphere -- DELETE THIS IF DATA IS AVAILABLE
N=1; %counter
Point=1; %secondary counter
Q=15; %amount of data points the sphere has
r=20; %radius of the sphere
[X,Y,Z] = sphere(Q); %generating coordinates
%count=Q+1;
count=length(X);
M=zeros(((Q+1)^2),3); %assigning a matrix M to speed up code.
for N=1:(count)
M(((N-1)*count)+1:N*count,1)=r*X(N,:); %%rewriting to one matrix
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
%%end of code of sphere
count=sqrt(length(M));
count2=length(M);
seen=nan(count2,3); %filling a "seen" matrix in which the points are located that have been "seen".
%%generating a double projected sphere
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]; %the 0.8 is an overlap factor, smaller means more overlap
end
end
P=twohalves(:,1:2);
[~, I, ~] = unique(P,'first','rows');
I = sort(I);
P = P(I,:);
twohalves=P;
%%start triangulation, and start of the problems
dt = alphaShape(twohalves(:,1:2),(r/4));
[tri,GG] = alphaTriangulation(dt)
[t,QQ] = tsearchn(P,tri,[0,0]) %searches for point 0,0 -> gives t, row number in tri and QQ = baricentric coordinates
%trimesh(tri,GG(:,1),GG(:,2))
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) %select the triangle ID of the triangle closest to the point generated by the random generator
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!

采纳的回答

luc
luc 2014-12-18
Couldn't find a good fix between indices from the two functions, so I wrote my own.
It's probably sub-efficient, but it works.
If any has any comments, please add some :)
seen=[0,0.1,0];
for n=1:length(GG)
punt=seen(:,1:2);
punt=seen(1,1:2);
dist(n,:)=pdist([punt;GG(n,:)]);
end
[m mi] = sort(dist)
lowest3index = mi(1:3)
lowest3Y = dist(lowest3index)
%GYT=find(tri(:,1:3)==[52 175 151])
pre=ismember(tri,lowest3index')
albis=pre*[1;1;1]
[indices,yolo] = find(albis == 3)
triplot(tri(indices,:),GG(:,1),GG(:,2))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Delaunay Triangulation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by