MCPcopy Create free account
hub / github.com/Apress/python-for-matlab-development / run_oo_sim

Function run_oo_sim

code/OO/Ball.py:47–68  ·  view source on GitHub ↗
(N, n_iter)

Source from the content-addressed store, hash-verified

45 return sep < sum_r
46
47def run_oo_sim(N, n_iter):
48 box_x, box_y = 10., 6.
49 r_min, r_max = 0.1, 0.3
50 print(f'n balls={N}')
51 for i in range(n_iter):
52 balls = []
53 for j in range(N):
54 x = r_max + (box_x-2*r_max)*rand()
55 y = r_max + (box_y-2*r_max)*rand()
56 R = 0.1 + 0.8*rand()
57 balls.append( Ball(x,y,R) )
58
59 coll = np.eye(N, dtype=np.bool)
60 T_s = time.time()
61 for j in range(N):
62 for k in range(j+1,N):
63 coll[j,k] = balls[j].collides_with(balls[k])
64 coll[k,j] = coll[j,k]
65
66 n_coll = (np.sum(coll) - N)//2
67 print(f'n coll={n_coll} Hz = '
68 f'{1/(time.time()-T_s):.2f}')
69
70def main():
71 run_oo_sim(1000, 10)

Callers 1

mainFunction · 0.85

Calls 2

BallClass · 0.85
collides_withMethod · 0.80

Tested by

no test coverage detected