Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* Number of data points *)
- numpts = 5;
- (* Test data set *)
- pts = {{0, 0}, {1, 0}, {0, 1}, {1, 1}, {0.3, 0.4}};
- dmesh = DelaunayMesh[pts];
- (* Extract the triangle list from the Delaunay triangulation *)
- tris = MeshCells[dmesh, 2];
- numtris = Length[tris];
- (* This demonstrates how to access the pts from the tris list *)
- Print["Number of triangles numtris = ", numtris];
- Do[
- Print["Tri ", i,
- " v1=", pts[[tris[[i, 1, 1]]]],
- " v2=", pts[[tris[[i, 1, 2]]]],
- " v3 = ", pts[[tris[[i, 1, 3]]]]],
- {i, 1, numtris}
- ];
- (* Data structure to hold neighbor data *)
- nghbrs = Table[{0, 0, 0}, {i, 1, numtris}];
- getVertexOpposingEdges = Compile[{{t, _Integer, 1}},
- {{t[[2]], t[[3]]}, {t[[3]], t[[1]]}, {t[[1]], t[[2]]}},
- CompilationTarget -> "C",
- RuntimeAttributes -> {Listable},
- Parallelization -> True,
- RuntimeOptions -> "Speed"
- ];
- pts = RandomReal[{-1, 1}, {25, 2}];
- M = DelaunayMesh[pts];
- n = MeshCellCount[M, 0]
- triangles = Developer`ToPackedArray[MeshCells[M, 2][[All, 1]]];
- vertexopposingedges = Flatten[getVertexOpposingEdges[triangles], 1];
- triangleLeftToEdge = SparseArray[
- vertexopposingedges -> Join @@ Transpose[{Range[Length[triangles]]}[[ConstantArray[1, 3]]]],
- {n, n}, -1
- ];
- reversededges = Transpose[Reverse[Transpose[vertexopposingedges]]];
- neighbortriangles = Partition[Extract[triangleLeftToEdge, reversededges], 3];
- Manipulate[
- HighlightMesh[
- M, {
- Style[{{2, i}}, ColorData[97][4]],
- Labeled[Style[Thread[{0, triangles[[i]]}], ColorData[97][2]],
- "Index"],
- Labeled[
- Style[Thread[{2, DeleteCases[neighbortriangles[[i]], -1]}],
- ColorData[97][3]], "Index"]
- }
- ],
- {i, 1, Length[triangles], 1}]
Add Comment
Please, Sign In to add comment