4
$\begingroup$

I have seen this question, but what I want is a bit different.

I have a set of data (blue points) and I would like to end up with something like this:

enter image description here,

i.e. joining each site with all its (nearest) neighbours.

The order of the data points is random so if I just do Joined->True it plots lines at random.

I know I can use Nearest[], so I added a line

x0 = Neartest[data]

which outputs a set of sets of numbers (the nearest neighbours), but am not quite sure how to plot that on top of the original points WITH segments in between.

Any pointers?

Thanks


if you want, the data is:

data= Uncompress@Import["http://pastebin.com/raw.php?i=qvMp8BNv"]
$\endgroup$
  • 2
    $\begingroup$ Look up DelaunayMesh[]. $\endgroup$ – J. M. is away Nov 12 '15 at 13:12
  • 2
    $\begingroup$ What exactly do you means by "all its nearest neighbors"? It is important to define this precisely. If you connect each dot to the one that is closes to it, you will not end up with the sort of figure you have drawn. Typically each dot will have a single nearest neighbour. BTW NearestNeighborGraph will do just that. $\endgroup$ – Szabolcs Nov 12 '15 at 13:15
  • $\begingroup$ Yeah I realise that's a bit misleading sorry. I meant all the points around a given datum... $\endgroup$ – SuperCiocia Nov 12 '15 at 13:31
  • $\begingroup$ I think DelaunayMesh is the one I want. By chance, is there any way of telling it what polygons to fit? Eg. "only try to draw pentagons" $\endgroup$ – SuperCiocia Nov 12 '15 at 14:01
  • $\begingroup$ I don't think that it does, since it performs a Delaunay triangulation which exclusively generates triangles. $\endgroup$ – IPoiler Nov 12 '15 at 15:44
7
$\begingroup$

here is the nearest neighbors plot:

pts = RandomReal[{-1, 1}, {200, 2}];
near = Nearest[pts];
Graphics[{Function[{pt}, Line[{pt, #}] & /@ near[pt, {5, .2}]] /@ pts,
         PointSize[.015], Red, Point@pts}]

this is up to 5 near neighbors within radius of .2..

enter image description here

for comparison DelaunayMesh[pts]

enter image description here

$\endgroup$
  • $\begingroup$ The comparison is a good hint. $\endgroup$ – user9660 Nov 12 '15 at 19:15

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.