Guest User

Untitled

a guest
Apr 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. (* Number of data points *)
  2. numpts = 5;
  3. (* Test data set *)
  4. pts = {{0, 0}, {1, 0}, {0, 1}, {1, 1}, {0.3, 0.4}};
  5. dmesh = DelaunayMesh[pts];
  6. (* Extract the triangle list from the Delaunay triangulation *)
  7. tris = MeshCells[dmesh, 2];
  8. numtris = Length[tris];
  9. (* This demonstrates how to access the pts from the tris list *)
  10. Print["Number of triangles numtris = ", numtris];
  11. Do[
  12. Print["Tri ", i,
  13. " v1=", pts[[tris[[i, 1, 1]]]],
  14. " v2=", pts[[tris[[i, 1, 2]]]],
  15. " v3 = ", pts[[tris[[i, 1, 3]]]]],
  16. {i, 1, numtris}
  17. ];
  18. (* Data structure to hold neighbor data *)
  19. nghbrs = Table[{0, 0, 0}, {i, 1, numtris}];
  20.  
  21. getVertexOpposingEdges = Compile[{{t, _Integer, 1}},
  22. {{t[[2]], t[[3]]}, {t[[3]], t[[1]]}, {t[[1]], t[[2]]}},
  23. CompilationTarget -> "C",
  24. RuntimeAttributes -> {Listable},
  25. Parallelization -> True,
  26. RuntimeOptions -> "Speed"
  27. ];
  28.  
  29. pts = RandomReal[{-1, 1}, {25, 2}];
  30. M = DelaunayMesh[pts];
  31. n = MeshCellCount[M, 0]
  32. triangles = Developer`ToPackedArray[MeshCells[M, 2][[All, 1]]];
  33.  
  34. vertexopposingedges = Flatten[getVertexOpposingEdges[triangles], 1];
  35.  
  36. triangleLeftToEdge = SparseArray[
  37. vertexopposingedges -> Join @@ Transpose[{Range[Length[triangles]]}[[ConstantArray[1, 3]]]],
  38. {n, n}, -1
  39. ];
  40.  
  41. reversededges = Transpose[Reverse[Transpose[vertexopposingedges]]];
  42. neighbortriangles = Partition[Extract[triangleLeftToEdge, reversededges], 3];
  43.  
  44. Manipulate[
  45. HighlightMesh[
  46. M, {
  47. Style[{{2, i}}, ColorData[97][4]],
  48. Labeled[Style[Thread[{0, triangles[[i]]}], ColorData[97][2]],
  49. "Index"],
  50. Labeled[
  51. Style[Thread[{2, DeleteCases[neighbortriangles[[i]], -1]}],
  52. ColorData[97][3]], "Index"]
  53. }
  54. ],
  55. {i, 1, Length[triangles], 1}]
Add Comment
Please, Sign In to add comment