When using alpha shape and the alpha radius is not specified. How does MATLAB obtain it? I want to understand it.

22 ビュー (過去 30 日間)
Hi everyone,
I just want to understand how MATLAB obtain such value, it is an optimization process? or alpha-shape is evaluated under different alpha radius? Is there a function to evaluate if the alpha shape does not have holes?

採用された回答

John D'Errico
John D'Errico 2019 年 6 月 20 日
編集済み: John D'Errico 2019 年 6 月 20 日
I don't have access to the code, so I can only surmise (since I've written alpha shape codes before in MATLAB, but not the one in question) ...
From the help, we see:
SHP = alphaShape(X,Y,A) creates a 2D alpha shape of the points (X,Y),
with alpha radius A. X and Y are column vectors that specify the
coordinates. A is a positive scalar that defines the alpha radius. If
A is not specified, the default is the smallest alpha that produces an
alpha shape enclosing all of the points.
The basic idea behind an alpha shape is that we start with a delaunay triangulation. We can think of that as an alpha shape with an alpha ball of infinite radius
xy = randn(100,2);
>> S = alphaShape(xy,inf)
S =
alphaShape with properties:
Points: [100×2 double]
Alpha: Inf
HoleThreshold: 0
RegionThreshold: 0
The alpha ball erodes into the triangulation. If a ball of radius alpha can penetrate a triangle and touch an interior point, then the triangle is effectively deleted from the list. (It has been many years since I wrote alpha shape codes of my own, but this is the essential idea.)
We can see however, that if we reduce alpha from infinity, that gradually we will eliminate those triangles around the edges of the domain. That is the goal of an alpha shape. But how far do we go? The default, as we are told, is the radius that does not cause any points to be deleted from the shape.
S = alphaShape(xy)
S =
alphaShape with properties:
Points: [100×2 double]
Alpha: 0.59772
HoleThreshold: 0
RegionThreshold: 0
plot(S)
hold on
plot(xy(:,1),xy(:,2),'ro')
So the default value was chosen to be 0.59772. Smaller than that? The alpha ball can erode some points effectively out of existence, by deleting all triangles tht contined those points s vertices.
S2 = alphaShape(xy,0.4)
S2 =
alphaShape with properties:
Points: [100×2 double]
Alpha: 0.4
HoleThreshold: 0
RegionThreshold: 0
plot(S2)
hold on
plot(xy(:,1),xy(:,2),'ro')
However, again, I don't have the code. And it looks like the choice of a default for alpha is a moderately crude one. Since if I choose a slightly smaller value for alpha than the default, the shape still contains all the original points as vertices.
S3 = alphaShape(xy,0.58)
S3 =
alphaShape with properties:
Points: [100×2 double]
Alpha: 0.58
HoleThreshold: 0
RegionThreshold: 0
But if you plot it, visually, this seems to be identical to that from the default value. That means the phrase we read:
the default is the smallest alpha that produces an
alpha shape enclosing all of the points
was only an approximation.
So clearly the scheme used to compute a default alpha is a moderately crude one, ad hoc, but not an optimization of any sort. I can imagine some schemes I might choose. What I need to recognize is the author of the code wanted to choose a scheme that was efficient. That suggests a sort of greedy algorithm. Once an alpha is identified that does reasonably well by some criteria, the search stops.
The question might be, what would I have done? I might start with the list of edges.
tri = DT.ConnectivityList;
edgelist = [tri(:,[1 2]);tri(:,[1 3]);tri(:,[2 3])];
edgelist = unique(sort(edgelist,2),'rows');
edgelens = sqrt(sum(xy(edgelist(:,1),:) - xy(edgelist(:,2),:)).^2,2);
Now, get the median edgelength.
median(edgelens)
ans =
0.36336
So this gives me some measure of what a number that is surely going to be too small for alpha. I might try creating an alpha shape with that as alpha. If no points get deleted, then I would be done. Otherwise, I might just increase that value by some fraction, testing to look for a value where no points get deleted. But clearly the search that is done is an ad hoc, approximate one. And sadly, I cannot know better than that. (Since I am not an employee.)

その他の回答 (1 件)

Sascha Hein
Sascha Hein 2021 年 5 月 25 日
Hi John,
very interesting thread. I was hoping you might be able to help with a similar problem:
I have this fairly large data base of ~15K XYZ values stored in a vector called "P".
When I run the bit of code bellow with the distance set to 1, I get a value for numtetrahedra = 74146
However, when the distance is set to 10 instead, I get a value for numtetrahedra = 81420
What I'm after is the amount of data points in each of the two plots. It seems paradoxical to me that the number of tetrahdra should increase when the distance is increased and the plots don't seem to show that. They behave as expected, that is, the larger the distance the smaller the number of tetrahdra...
shp = alphaShape(P,1);
plot(shp)
tri = alphaTriangulation(shp);
numtetrahedra = size(tri,1)

カテゴリ

Help Center および File ExchangeBounding Regions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by