Message Boards Message Boards

0
|
5282 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Cell indices and cell coordinates from Voronoi diagram

Dear All,

Let's say I have a Voronoi diagram of some points:

voronoidata=VoronoiMesh[0.5+{{9,86},{89,64},{28,49},{21,47},{31,70},{6,36},{3,24},{68,75},{25,55},{47,21}}]

this will get me the Voronoi mesh:

enter image description here

I know I can do MeshCoordinates[voronoidata] to get the coordinates of the mesh. How do I get the indices to make the polygons:

basically what I want are the indices:

ToExpression[StringReplace[ToString[voronoidata//FullForm],"MeshRegion"->"List"]][[2]]

{Polygon[{{11, 6, 10, 2}, {18, 4, 13, 22}}], 
 Polygon[{{16, 9, 17, 20, 21}, {1, 3, 7, 2, 10}, {5, 1, 10, 6,8}, {15, 11, 2, 7, 14}, {13, 4, 5, 8, 12}, {14, 7, 3, 9, 16}}], 
 Polygon[{{19, 12, 8, 6, 11, 15}}], 
 Polygon[{{17, 9, 3, 1, 5, 4, 18}}]}

I would consider this to be a 'hack' as voronoidata is an atom, however the data can still be seen by FullForm(?) This procedure is however a bit cumbersome as you understand...

POSTED BY: Sander Huisman
3 Replies
Posted 9 years ago
MeshCells[voronoidata, 2]
{Polygon[{11, 6, 10, 2}], Polygon[{18, 4, 13, 22}],   Polygon[{16, 9,
17, 20, 21}], Polygon[{1, 3, 7, 2, 10}],   Polygon[{5, 1, 10, 6, 8}],
 Polygon[{15, 11, 2, 7, 14}],   Polygon[{13, 4, 5, 8, 12}],
 Polygon[{14, 7, 3, 9, 16}],   Polygon[{19, 12, 8, 6, 11, 15}],
 Polygon[{17, 9, 3, 1, 5, 4, 18}]}
POSTED BY: Jaebum Jung

Thank @Jaebum Jung! That was easy, feel kinda embarrassed! I somehow missed the MeshCells function...Thanks for the help!

POSTED BY: Sander Huisman

MeshPrimitives looked like a good function, however this returns the 'real' coordinates, not the indices...

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract