I'm trying to simulate to teams, so that I can see the grouping of players on one team. Here is what I have in mind:


I have tried making a nearest neighbor graph between all players then deleting the vertices of one team, but the connections pass through red "cells" (eg 16 to 20).

not working

Also, a nearest neighbor graph of one team does not always connect adjacent cells (eg 19 to 16) and passes through red cells (eg 14 to 18).

not working either

Here is the full code with everything I have above:

ptt = RandomReal[{0, 10}, {22, 2}];
ntt = NearestNeighborGraph[ptt[[11 ;; 22]], 1, 
   VertexLabels -> Table[ptt[[i]] -> i, {i, 11, 22}]];
(* ntt = vertexDeleteKeepEmbedding[ntt,Table[VertexList[ntt][[n]],{n,\
1,11}]] *)
Show[Show[VoronoiMesh[ptt], ntt], 
 Graphics[{PointSize@Medium, Red, Point[ptt[[1 ;; 11]]], Blue, 
   Point[ptt[[12 ;; 22]]]}]]

vertexDeleteKeepEmbedding[graph_, vertex_] := 
  Module[{coords, vertices = VertexList[graph]}, 
   coords = 
    DeleteCases[vertices, vertex] /. 
     Thread[vertices -> GraphEmbedding[graph]];
   Graph[VertexDelete[graph, vertex], VertexCoordinates -> coords]];

Any tips?

  • $\begingroup$ Confusing tipic... $\endgroup$ – yode Jul 4 '17 at 14:29
  • $\begingroup$ In one sentence I want to find groups of blue/red vertexes that don't intersect cells from the other team $\endgroup$ – Robert Jul 4 '17 at 14:42
pts = RandomReal[{0, 10}, {22, 2}];
{team1, team2} = {pts[[;; 11]], pts[[12 ;;]]};

Is this what you after?

teams = GroupBy[Complement[Sort /@ DelaunayMesh[pts]["EdgeCoordinates"], 
    Sort /@ Tuples[{team1, team2}]],MemberQ[team1, First[#]] &];
VoronoiMesh[pts,Epilog -> {PointSize[.02], Red, Point[team1], Line[teams[True]], 
   Blue, Point[team2], Line[teams[False]]}]

Mathematica graphics

PS:Note the graph of DelaunayMesh record the relationship about the vertices of VoronoiMesh.

  • $\begingroup$ Thank you for your answer! $\endgroup$ – Robert Jul 4 '17 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.