0
$\begingroup$

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:

example

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?

$\endgroup$
2
  • $\begingroup$ Confusing tipic... $\endgroup$
    – yode
    Jul 4, 2017 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$
    – rawsh
    Jul 4, 2017 at 14:42

1 Answer 1

2
$\begingroup$
SeedRandom[1]
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.

$\endgroup$
1
  • $\begingroup$ Thank you for your answer! $\endgroup$
    – rawsh
    Jul 4, 2017 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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