print_pores.py 1.52 KB
Newer Older
sfritschi's avatar
sfritschi committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import numpy as np

def cell_pos(pos):
    from math import floor
    return [floor(pos[i] + 3.) for i in range(2)]

def is_periodic(cellPos):
    return not all([2 <= cellPos[i] and cellPos[i] <= 3 for i in range(2)])

def print_point(x, y):
    x = np.round(x, 2)
    y = np.round(y, 2)
    print("\\node[black] at (%.2f, %.2f) {\\textbullet};" % (x, y))
    
if __name__ == '__main__':
    nInterior = 10
sfritschi's avatar
sfritschi committed
17
    nRest = 34
sfritschi's avatar
sfritschi committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    
    interiorX = np.random.uniform(-2, 1, (nInterior, 1)) 
    interiorY = np.random.uniform(-1, 2, (nInterior, 1))
    
    interior = np.hstack((interiorX, interiorY))
    rest = np.random.uniform(-2, 2, (nRest, 2))
    
    points = np.vstack((interior, rest))
    
    for i in range(points.shape[0]):
        pos = points[i, :]
        cellPos = cell_pos(pos)
        x = pos[0]
        y = pos[1]
        
        print_point(x, y)
        if (is_periodic(cellPos)):
            # Left/right side
            if (x <= -1.):
                print_point(x + 4., y)
            elif (x >= 1.):
                print_point(x - 4., y)
            
            # Up/down side
            if (y <= -1.):
                print_point(x, y + 4.)
sfritschi's avatar
sfritschi committed
44
45
46
47
                if (x <= -1.):
                    print_point(x + 4., y + 4.)
                elif (x >= 1.):
                    print_point(x - 4., y + 4.)
sfritschi's avatar
sfritschi committed
48
49
            elif (y >= 1.):
                print_point(x, y - 4.)
sfritschi's avatar
sfritschi committed
50
51
52
53
                if (x <= -1.):
                    print_point(x + 4., y - 4.)
                elif (x >= 1.):
                    print_point(x - 4., y - 4.)