2

As this shows, you can use it to filter a delaunay triangulation and get a perfect limit.

Can anybody explain the magik algorithm?

VividD
  • 10,456
  • 6
  • 64
  • 111
civiltomain
  • 1,136
  • 1
  • 9
  • 27

2 Answers2

5

Background

There isn't really much magic beyond classic Delaunay triangulation algorithm, which is implemented as function d3.geom.delaunay() within D3.

In the example you linked to, alpha shapes are implemented as modified Delaunay triangulation, in such a way so that any triangle that has at least one side larger than alpha (in the example it has value 50) is removed from triangulation.

That's why the result looks like this: (original vertexes, Delaunay triangulation, and Alpha shape)

enter image description here

Details

d3.geom.delaunay() returns array of triangles, so this code:

mesh = d3.geom.delaunay(offset(vertices,600,0)).filter(function(t) {
    return dsq(t[0],t[1]) < asq && dsq(t[0],t[2]) < asq && dsq(t[1],t[2]) < asq;
});

together with fact that asq is alpha squared, and dsq() is function that computes squared distance between two points in the plane, causes removing any triangle with at least one side larger than alpha, which in turn produces the third image in the picture above.

Hope this helps.

VividD
  • 10,456
  • 6
  • 64
  • 111
  • Thanks @VividD. mmm The theoretycal explanation is very complicated for me and ... In addition '50' is an arbitrary value, isn't it ? Would not it have more sense an angular value? Thanks anyway – civiltomain May 26 '14 at 16:54
  • The answer is right: d3.geom.delaunay() returns array of triangles, it is also reflected in the term "delaunay triangulation". So, the most logical way of removing something unneeded from a triangulation is to remove triangles. :) @Phpdna – VividD Jun 03 '14 at 17:46
  • Some of the sides of deleted triangles are shared with triangles that remain undeleted, so, yes, something will remain in the picture. – VividD Jun 04 '14 at 08:50
  • t[0], t[1], and t[2] are vertexes of the current triangle. – VividD Jun 04 '14 at 13:09
0

Alpha shapes is when you remove any edges exceeding alpha from the delaunay triangulation. You can either use lines or disks to show alpha visually but the goal is to find a concave hull. Read here to find the concave hull:Calculate bounding polygon of alpha shape from the Delaunay triangulation.

Community
  • 1
  • 1
Micromega
  • 12,486
  • 7
  • 35
  • 72