# Given a cell in a Voronoi diagram, which point did it come from? [duplicate]

Given a set of points

pts = Table[{RandomReal[], RandomReal[]}, {i, 1, 10}];


and their Voronoi diagram

vor = VoronoiMesh[pts];


I can list the 2-dimensional cells as follows:

cells=MeshCells[vor, 2];


Given an element from this list, say

cells[[5]]


How do I recover the coordinates of the point from pts that is contained in that cell?

## marked as duplicate by m_goldberg, MarcoB, Alex Trounev, Thies Heidecke, MikeLimaOscarJun 21 at 16:22

You can use RegionMeshMeshNearestCellIndex to construct Associations mapping faces to points and points to faces

faceToPoint = Association[RegionMeshMeshNearestCellIndex[vor, #] -> # & /@ pts]


{{2, 5} -> {0.817389, 0.11142}, {2, 1} -> {0.789526, 0.187803}, {2,    7} -> {0.241361, 0.0657388}, {2, 9} -> {0.542247, 0.231155}, {2,    10} -> {0.396006, 0.700474}, {2, 2} -> {0.211826, 0.748657}, {2,    3} -> {0.422851, 0.247495}, {2, 4} -> {0.977172, 0.825163}, {2, 8} -> {0.925275, 0.578056}, {2, 6} -> {0.29287, 0.208051}}

pointToFace = Association[# -> RegionMeshMeshNearestCellIndex[vor, #] & /@ pts]


<|{0.817389, 0.11142} -> {2, 5}, {0.789526, 0.187803} -> {2,    1}, {0.241361, 0.0657388} -> {2, 7}, {0.542247, 0.231155} -> {2,    9}, {0.396006, 0.700474} -> {2, 10}, {0.211826, 0.748657} -> {2,    2}, {0.422851, 0.247495} -> {2, 3}, {0.977172, 0.825163} -> {2,    4}, {0.925275, 0.578056} -> {2, 8}, {0.29287, 0.208051} -> {2, 6}|>

k = 5;
Show[HighlightMesh[vor, {2, k}],
Graphics[{Red, PointSize[Large], Point @ faceToPoint[{2, k}]}]]


For k = 8 we get