How to group points based on mesh primitive membership

This is possible already in version 12, but just undocumented.

grouped =  GatherBy[points, Region`Mesh`MeshNearestCellIndex[randMesh]];

Apparently, this can find only top-dimensional cells. This is a good example where the syntax of undocumented code was changed in the final version.


In version 12.1 you can use NearestMeshCells with GatherBy as follows:

grouped = GatherBy[points, NearestMeshCells[{randMesh, 2}, #] &];

Show[randMesh, 
 ListPlot[grouped, BaseStyle -> PointSize[Large], 
  PlotLegends -> ("group-" <> ToString[#] & /@ Range[Length @ grouped])]]

enter image description here