项目作者: stla

项目描述 :
Delaunay triangulation, Voronoi diagrams and convex hulls in arbitrary dimension.
高级语言: R
项目地址: git://github.com/stla/qhull.git
创建时间: 2018-01-25T02:40:29Z
项目社区:https://github.com/stla/qhull

开源协议:

下载


qhull

Delaunay triangulation, Voronoi diagrams and convex hulls.
Based on the qhull C library.

Delaunay tesselation

Consider this list of vertices (actually these are the vertices of a
polyhedron):

  1. vertices = [
  2. [ -5, -5, 16 ] -- 0
  3. , [ -5, 8, 3 ] -- 1
  4. , [ 4, -1, 3 ] -- 2
  5. , [ 4, -5, 7 ] -- 3
  6. , [ 4, -1, -10 ] -- 4
  7. , [ 4, -5, -10 ] -- 5
  8. , [ -5, 8, -10 ] -- 6
  9. , [ -5, -5, -10 ] -- 7
  10. ]

The delaunay function splits the polyhedron into simplices, the tiles of the
tesselation:

  1. > import Delaunay
  2. > d <- delaunay vertices False False
  3. > _tiles d
  4. fromList
  5. [ ( 0
  6. , Tile
  7. { _simplex =
  8. Simplex
  9. { _points =
  10. fromList
  11. [ ( 2 , [ 4.0 , -1.0 , 3.0 ] )
  12. , ( 4 , [ 4.0 , -1.0 , -10.0 ] )
  13. , ( 5 , [ 4.0 , -5.0 , -10.0 ] )
  14. , ( 7 , [ -5.0 , -5.0 , -10.0 ] )
  15. ]
  16. , _circumcenter =
  17. [ -0.5000000000000009 , -3.0 , -3.499999999999999 ]
  18. , _circumradius = 8.154753215150047
  19. , _volume = 78.0
  20. }
  21. , _neighborsIds = fromList [ 1 , 3 ]
  22. , _facetsIds = fromList [ 0 , 1 , 2 , 3 ]
  23. , _family = Nothing
  24. , _toporiented = False
  25. }
  26. )
  27. , ( 1
  28. , Tile
  29. { _simplex =
  30. ......

The field _tiles is a map of Tile objects. The keys of the map are
the tiles identifiers. A Tile object has five fields:

  • _simplex, a Simplex object;

  • _neighborsIds, a set of tiles identifiers, the neighbors of the tile;

  • facetsIds, a set of facets identifiers, the facets of the tile;

  • family, two tiles of the same family share the same circumcenter;

  • toporiented, Boolean, whether the tile is top-oriented.

A Simplex object has four fields:

  • _points, the vertices of the simplex, actually a map of the vertices
    identifiers to their coordinates

  • _circumcenter, the coordinates of the circumcenter of the simplex;

  • _circumradius, the circumradius;

  • _volume, the volume of the simplex (the area in dimension 2, the
    length in dimension 1).

Another field of the output of delaunay is _tilefacets:

  1. > _tilefacets d
  2. fromList
  3. [ ( 0
  4. , TileFacet
  5. { _subsimplex =
  6. Simplex
  7. { _points =
  8. fromList
  9. [ ( 4 , [ 4.0 , -1.0 , -10.0 ] )
  10. , ( 5 , [ 4.0 , -5.0 , -10.0 ] )
  11. , ( 7 , [ -5.0 , -5.0 , -10.0 ] )
  12. ]
  13. , _circumcenter = [ -0.5000000000000009 , -3.0 , -10.0 ]
  14. , _circumradius = 4.924428900898053
  15. , _volume = 36.0
  16. }
  17. , _facetOf = fromList [ 0 ]
  18. , _normal = [ 0.0 , 0.0 , -1.0 ]
  19. , _offset = -10.0
  20. }
  21. )
  22. , ( 1
  23. , TileFacet
  24. { _subsimplex =
  25. ......

This is a map of TileFacet objects. A tile facet is a subsimplex. The keys of
the map are the identifiers of the facets.
A TileFacet object has four fields: _subsimplex, a Simplex object,
_facetOf, the identifiers of the tiles this facet belongs to (a set of one
or two integers), _normal, the normal of the facet, and offset, the offset
of the facet.

Finally, the output of delaunay has a _sites field, the vertices with
additional information:

  1. > _sites d
  2. fromList
  3. [ ( 0
  4. , Site
  5. { _point = [ -5.0 , -5.0 , 16.0 ]
  6. , _neighsitesIds = fromList [ 1 , 3 , 7 ]
  7. , _neighfacetsIds = fromList [ 15 , 16 , 17 ]
  8. , _neightilesIds = fromList [ 5 ]
  9. }
  10. )
  11. , ( 1
  12. , Site
  13. ......

This is a map of Site objects. The keys of the map are the identifiers of
the vertices. A Site object has four fields:

  • _point, the coordinates of the vertex;

  • _neighsitesIds, the identifiers of the connected vertices;

  • _neighfacetsIds, a set of integers, the identifiers of the facets the
    vertex belongs to;

  • _neightilesIds, the set of the identifiers of the tiles the vertex belongs
    to.

gfycat

Voronoi diagrams

The library allows to get the Voronoi diagram of a list of sites (vertices)
from the Delaunay tesselation. Here is a 3D example.

  1. centricCuboctahedron :: [[Double]]
  2. centricCuboctahedron = [[i,j,0] | i <- [-1,1], j <- [-1,1]] ++
  3. [[i,0,j] | i <- [-1,1], j <- [-1,1]] ++
  4. [[0,i,j] | i <- [-1,1], j <- [-1,1]] ++
  5. [[0,0,0]]
  6. import Delaunay
  7. import Voronoi3D
  8. d <- delaunay centricCuboctahedron False False
  9. v = voronoi3 d

In some circumstances, one has to run the Delaunay tesselation including the
degenerate tiles in order to get the correct Voronoi diagram, that is to say
delaunay vertices False True.

The output of voronoi3 is a list of Voronoi cells given as pairs, each pair
consisting of a site and a list of edges.
This is the cell of the center [0, 0, 0]:

  1. > last v
  2. ( [ 0.0 , 0.0 , 0.0 ]
  3. , [ Edge3 ( ( -0.5 , -0.5 , 0.5 ) , ( 0.0 , 0.0 , 1.0 ) )
  4. , Edge3 ( ( -0.5 , -0.5 , 0.5 ) , ( 0.0 , -1.0 , 0.0 ) )
  5. , Edge3 ( ( -0.5 , -0.5 , 0.5 ) , ( -1.0 , 0.0 , 0.0 ) )
  6. , Edge3 ( ( -0.5 , 0.5 , 0.5 ) , ( 0.0 , 0.0 , 1.0 ) )
  7. , Edge3 ( ( -0.5 , 0.5 , 0.5 ) , ( 0.0 , 1.0 , 0.0 ) )
  8. , Edge3 ( ( -0.5 , 0.5 , 0.5 ) , ( -1.0 , 0.0 , 0.0 ) )
  9. , Edge3 ( ( 0.5 , -0.5 , 0.5 ) , ( 0.0 , 0.0 , 1.0 ) )
  10. , Edge3 ( ( 0.5 , -0.5 , 0.5 ) , ( 0.0 , -1.0 , 0.0 ) )
  11. , Edge3 ( ( 0.5 , -0.5 , 0.5 ) , ( 1.0 , 0.0 , 0.0 ) )
  12. , Edge3 ( ( 0.5 , 0.5 , 0.5 ) , ( 0.0 , 0.0 , 1.0 ) )
  13. , Edge3 ( ( 0.5 , 0.5 , 0.5 ) , ( 0.0 , 1.0 , 0.0 ) )
  14. , Edge3 ( ( 0.5 , 0.5 , 0.5 ) , ( 1.0 , 0.0 , 0.0 ) )
  15. , Edge3 ( ( -0.5 , -0.5 , -0.5 ) , ( 0.0 , 0.0 , -1.0 ) )
  16. , Edge3 ( ( -0.5 , -0.5 , -0.5 ) , ( 0.0 , -1.0 , 0.0 ) )
  17. , Edge3 ( ( -0.5 , -0.5 , -0.5 ) , ( -1.0 , 0.0 , 0.0 ) )
  18. , Edge3 ( ( -0.5 , 0.5 , -0.5 ) , ( 0.0 , 0.0 , -1.0 ) )
  19. , Edge3 ( ( -0.5 , 0.5 , -0.5 ) , ( 0.0 , 1.0 , 0.0 ) )
  20. , Edge3 ( ( -0.5 , 0.5 , -0.5 ) , ( -1.0 , 0.0 , 0.0 ) )
  21. , Edge3 ( ( 0.5 , -0.5 , -0.5 ) , ( 0.0 , 0.0 , -1.0 ) )
  22. , Edge3 ( ( 0.5 , -0.5 , -0.5 ) , ( 0.0 , -1.0 , 0.0 ) )
  23. , Edge3 ( ( 0.5 , -0.5 , -0.5 ) , ( 1.0 , 0.0 , 0.0 ) )
  24. , Edge3 ( ( 0.5 , 0.5 , -0.5 ) , ( 0.0 , 0.0 , -1.0 ) )
  25. , Edge3 ( ( 0.5 , 0.5 , -0.5 ) , ( 0.0 , 1.0 , 0.0 ) )
  26. , Edge3 ( ( 0.5 , 0.5 , -0.5 ) , ( 1.0 , 0.0 , 0.0 ) )
  27. ]
  28. )

This is a bounded cell: it has finite edges only. The other ones are not
bounded, they have infinite edges:

  1. > head v
  2. ( [ -1.0 , -1.0 , 0.0 ]
  3. , [ Edge3 ( ( -0.5 , -0.5 , 0.5 ) , ( 0.0 , -1.0 , 0.0 ) )
  4. , Edge3 ( ( -0.5 , -0.5 , 0.5 ) , ( -1.0 , 0.0 , 0.0 ) )
  5. , IEdge3
  6. ( ( -0.5 , -0.5 , 0.5 )
  7. , ( -0.5773502691896258 , -0.5773502691896258 , 0.5773502691896258 )
  8. )
  9. , Edge3 ( ( -0.5 , -0.5 , -0.5 ) , ( 0.0 , -1.0 , 0.0 ) )
  10. , Edge3 ( ( -0.5 , -0.5 , -0.5 ) , ( -1.0 , 0.0 , 0.0 ) )
  11. , IEdge3
  12. ( ( -0.5 , -0.5 , -0.5 )
  13. , ( -0.5773502691896258 , -0.5773502691896258 , -0.5773502691896258 )
  14. )
  15. , IEdge3 ( ( -1.0 , 0.0 , 0.0 ) , ( 1.0 , 0.0 , 0.0 ) )
  16. , IEdge3 ( ( 0.0 , -1.0 , 0.0 ) , ( 0.0 , -1.0 , 0.0 ) )
  17. ]
  18. )

gfycat

Convex hull

The convexHull function of the ConvexHull module generates the convex hull
of a list of points.

  1. import ConvexHull
  2. import ConvexHull.Examples -- for the function randomInCube
  3. points <- randomInCube 100 -- 100 random points in a cube
  4. hull <- convexHull points False False Nothing

The vertices of the convex hull are stored in the field _hvertices:

  1. > _hvertices hull
  2. fromList
  3. [ ( 3
  4. , Vertex
  5. { _point =
  6. [ 0.7872072051657094 , 0.450772463858757 , 1.9900427529711773e-2 ]
  7. , _neighfacets = fromList [ 42 , 43 , 47 , 48 ]
  8. , _neighvertices = fromList [ 1 , 11 , 64 , 88 ]
  9. , _neighridges = fromList [ 70 , 71 , 72 , 77 ]
  10. }
  11. )
  12. , ( 6
  13. , Vertex
  14. ......

The edges in the field _hedges:

  1. > _hedges hull
  2. fromList
  3. [ ( Pair 14 70
  4. , ( [ 0.9215432980174852 , 0.8554065771602318 , 0.9842902519648512 ]
  5. , [ 0.9497713758656887 , 0.998006476041318 , 0.7243639875028591 ]
  6. )
  7. )
  8. , ( Pair 84 99
  9. ......

The facets in the field _hfacets:

  1. > _hfacets hull
  2. fromList
  3. [ ( 0
  4. , Facet
  5. { _fvertices =
  6. fromList
  7. [ ( 4
  8. , [ 1.5757133629105136e-3
  9. , 0.6442797662244039
  10. , 0.7058559215899725
  11. ]
  12. )
  13. , ( 67
  14. , [ 2.7500520534961326e-2
  15. , 0.37516259577251554
  16. , 0.7331611715042575
  17. ]
  18. )
  19. , ( 77
  20. , [ 3.46399386146774e-2
  21. , 5.575911794526589e-2
  22. , 0.46787034305814157
  23. ]
  24. )
  25. ]
  26. , _fridges =
  27. fromList
  28. [ ( 0
  29. , Ridge
  30. { _rvertices =
  31. fromList
  32. [ ( 4
  33. , [ 1.5757133629105136e-3
  34. , 0.6442797662244039
  35. , 0.7058559215899725
  36. ]
  37. )
  38. , ( 77
  39. , [ 3.46399386146774e-2
  40. , 5.575911794526589e-2
  41. , 0.46787034305814157
  42. ]
  43. )
  44. ]
  45. , _ridgeOf = fromList [ 0 , 4 ]
  46. }
  47. )
  48. , ( 1
  49. , Ridge
  50. { _rvertices =
  51. fromList
  52. [ ( 4
  53. , [ 1.5757133629105136e-3
  54. , 0.6442797662244039
  55. , 0.7058559215899725
  56. ]
  57. )
  58. , ( 67
  59. , [ 2.7500520534961326e-2
  60. , 0.37516259577251554
  61. , 0.7331611715042575
  62. ]
  63. )
  64. ]
  65. , _ridgeOf = fromList [ 0 , 2 ]
  66. }
  67. )
  68. , ( 2
  69. , Ridge
  70. { _rvertices =
  71. fromList
  72. [ ( 67
  73. , [ 2.7500520534961326e-2
  74. , 0.37516259577251554
  75. , 0.7331611715042575
  76. ]
  77. )
  78. , ( 77
  79. , [ 3.46399386146774e-2
  80. , 5.575911794526589e-2
  81. , 0.46787034305814157
  82. ]
  83. )
  84. ]
  85. , _ridgeOf = fromList [ 0 , 1 ]
  86. }
  87. )
  88. ]
  89. , _centroid =
  90. [ 2.1238724170849748e-2 , 0.3584004933140618 , 0.6356291453841239 ]
  91. , _normal =
  92. [ -0.9930268604214181
  93. , -8.766369712550202e-2
  94. , 7.882087723357102e-2
  95. ]
  96. , _offset = 2.40848904384814e-3
  97. , _area = 4.0339144929987907e-2
  98. , _neighbors = fromList [ 1 , 2 , 4 ]
  99. , _family = None
  100. , _fedges =
  101. fromList
  102. [ ( Pair 4 67
  103. , ( [ 1.5757133629105136e-3
  104. , 0.6442797662244039
  105. , 0.7058559215899725
  106. ]
  107. , [ 2.7500520534961326e-2
  108. , 0.37516259577251554
  109. , 0.7331611715042575
  110. ]
  111. )
  112. )
  113. , ( Pair 67 77
  114. , ( [ 2.7500520534961326e-2
  115. , 0.37516259577251554
  116. , 0.7331611715042575
  117. ]
  118. , [ 3.46399386146774e-2
  119. , 5.575911794526589e-2
  120. , 0.46787034305814157
  121. ]
  122. )
  123. )
  124. , ( Pair 4 77
  125. , ( [ 1.5757133629105136e-3
  126. , 0.6442797662244039
  127. , 0.7058559215899725
  128. ]
  129. , [ 3.46399386146774e-2
  130. , 5.575911794526589e-2
  131. , 0.46787034305814157
  132. ]
  133. )
  134. )
  135. ]
  136. }
  137. )
  138. , ( 1
  139. , Facet
  140. ......

gfycat

Halfspaces intersections

equation

  1. import HalfSpaces
  2. import Data.Ratio ((%))
  3. x = newVar 1
  4. y = newVar 2
  5. z = newVar 3
  6. constraints =
  7. [ x .>= 0 -- shortcut for x .>=. cst 0
  8. , x .<= 3
  9. , y .>= 0
  10. , y .<=. cst 2 ^-^ (2%3)*^x
  11. , z .>= 0
  12. , z .<=. cst 6 ^-^ 2*^x ^-^ 3*^y ]
  1. > hsintersections constraints False
  2. [ [ -1.1102230246251565e-16 , -1.1102230246251565e-16 , 6.0 ]
  3. , [ 0.0 , 2.0 , 0.0 ]
  4. , [ 0.0 , 0.0 , 0.0 ]
  5. , [ 3.0 , 0.0 , 0.0 ] ]

The convex hull of a curve on the sphere:

Imgur

The Voronoi cell of a point inside the Utah teapot:

Imgur

The Voronoi diagram of a projection of the truncated tesseract:

Imgur

The Voronoi diagram of a cube surrounded by three perpendicular circles:

Imgur