Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The function RandomGraph[SpatialGraphDistribution[n, r]] generates a random geometric graph over $[0,1]^2$ where vertices are connected if they are within a distance $r$ of one-another.

How would I explicitly specify a list of points for generating a random geometric graph using this function? Specifically, I need to enforce a minimum threshold distance between points.

Clarification: My point list is going to come from a Random Sequential Adsorption (RSA) simulation of circles on a plane. So I mean that no two points should be closer than some minimum threshold distance set by the radius of the circles being deposited, not that two points shouldn't share an edge if they are closer than the threshold distance.

share|improve this question
After reading the clarification, I'm not sure I understand what you're asking. Is this what you need? – Szabolcs Apr 9 '13 at 14:33
@Szabolcs Oh, no I'm just asking to be able to feed a set of points to SpatialGraphDistribution that I've already generated by simulating Random Sequential Adsorption (RSA). My understanding, from the literature, is that this random packing process must be simulated. – M.Y. Apr 10 '13 at 2:16
@Szabolcs I think you're answer is the answer I was looking for - it can't be done, so I have to rely on my own implementation. – M.Y. Apr 10 '13 at 2:16
up vote 1 down vote accepted

With SpatialGraphDistribution it's not possible, as this is used for representing a distribution. You were asking, "How would I explicitly specify a list of points for generating a random geometric graph", but if you give a set of points, then the graph is not random any more, so SpatialGraphDistribution won't be of use.

I would proceed like this:

Take a set of points (you'll already have this list from another source):

pts = RandomReal[1, {100, 2}];

Calculate pairwise distances:

distances = 
  With[{tr = Transpose[pts]}, 
   Function[point, Sqrt[Total[(point - tr)^2]]] /@ pts];

Build an adjacency matrix, taking care not to connect each node to itself:

am = UnitStep[r - distances] - IdentityMatrix@Length[pts];

Convert it to a graph:

AdjacencyGraph[am, VertexCoordinates -> pts]

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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