(n1, n2, k, r)
Calculates Coulomb forces and updates node data.
Calculates Coulomb forces and updates node data.
Calculates Coulomb forces and updates node data .
def _coulomb(n1, n2, k, r):
    """Calculates Coulomb forces and updates node data."""
    # Get relevant positional data
    delta = [x2 - x1 for x1, x2 in zip(n1['velocity'], n2['velocity'])]
    distance = sqrt(sum(d ** 2 for d in delta))

    # If the deltas are too small, use random values to keep things moving
    if distance < 0.1:
        delta = [uniform(0.1, 0.2) for _ in repeat(None, 3)]
        distance = sqrt(sum(d ** 2 for d in delta))

    # If the distance isn't huge (ie. Coulomb is negligible), calculate
    if distance < r:
        force = (k / distance) ** 2
        n1['force'] = [f - force * d for f, d in zip(n1['force'], delta)]
        n2['force'] = [f + force * d for f, d in zip(n2['force'], delta)]
def _coulomb ( n1 , n2 , k , r ) : # Get relevant positional data delta = [ x2 - x1 for x1 , x2 in zip ( n1 [ 'velocity' ] , n2 [ 'velocity' ] ) ] distance = sqrt ( sum ( d ** 2 for d in delta ) ) # If the deltas are too small, use random values to keep things moving if distance < 0.1 : delta = [ uniform ( 0.1 , 0.2 ) for _ in repeat ( None , 3 ) ] distance = sqrt ( sum ( d ** 2 for d in delta ) ) # If the distance isn't huge (ie. Coulomb is negligible), calculate if distance < r : force = ( k / distance ) ** 2 n1 [ 'force' ] = [ f - force * d for f , d in zip ( n1 [ 'force' ] , delta ) ] n2 [ 'force' ] = [ f + force * d for f , d in zip ( n2 [ 'force' ] , delta ) ]