drosofff
3/5/2017 - 3:59 PM

To do the Triangle network of Sacha

To do the Triangle network of Sacha

# recover the tabular output from the python script

coordinates = read.delim("/Users/aligre/Documents/segment_points.tab", header=F)
plot(1, type="n", xlim=c(2,25), ylim=c(2,25))
segments(coordinates$V1, coordinates$V2, coordinates$V3, coordinates$V4, lwd=2, col="darkgrey")
#!/usr/bin/env python

import sys
import math
import random

mindistance = 4

# liste_de_point = [(randint(0,30), randint(0,30)) for i in range(0,200)]
liste_de_point = []
for i in range(0,30,2):
    for j in range(0,30,2):
        liste_de_point.append((i,j))
print (liste_de_point)

liste_de_point_deformed = []
for tup in liste_de_point:
    x=tup[0]+random.uniform(-1,1)
    y=tup[1]+random.uniform(-1,1)
    liste_de_point_deformed.append((x,y))
liste_de_point = liste_de_point_deformed

points_dict = {}
for tup in liste_de_point:
    points_dict[tup]=[]

for point in points_dict:
    for pointinlist in liste_de_point:
        distance = math.sqrt((point[0]-pointinlist[0])**2 + (point[1]-pointinlist[1])**2)
        if 0 < distance < mindistance:
            points_dict[point].append(pointinlist)

for point in points_dict:
    for point2 in points_dict[point]:
        print "%s\t%s\t%s\t%s" % (point[0], point[1], point2[0], point2[1])