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

Function collision_matrix

code/OO/collision_matrix.py:35–45  ·  view source on GitHub ↗

Use broadcasting to return a square matrix of Boolean values with True at position [i,j] and [j,i] if circles i and j intersect.

(x, y, R)

Source from the content-addressed store, hash-verified

33import time
34
35def collision_matrix(x, y, R):
36 """
37 Use broadcasting to return a square matrix of Boolean
38 values with True at position [i,j] and [j,i] if
39 circles i and j intersect.
40 """
41 dx = x[:,np.newaxis] - x[np.newaxis,:]
42 dy = y[:,np.newaxis] - y[np.newaxis,:]
43 sep = np.sqrt( dx**2 + dy**2 )
44 sum_r = R[:,np.newaxis] + R[np.newaxis,:]
45 return sep < sum_r
46
47def run_sim(N, n_iter):
48 box_x, box_y = 10., 6.

Callers 1

run_simFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected