示例#1
0
 def force_as_dxdy(pixel_a: Pixel_xy, pixel_b: Pixel_xy,
                   screen_distance_unit, repulsive):
     """
     Compute the force between pixel_a pixel and pixel_b and return it as a velocity: direction * force.
     """
     direction: Velocity = normalize_dxdy((
         pixel_a - pixel_b) if repulsive else (pixel_b - pixel_a))
     d = pixel_a.distance_to(pixel_b, wrap=False)
     if repulsive:
         dist = max(
             1,
             pixel_a.distance_to(pixel_b, wrap=False) /
             screen_distance_unit)
         rep_coefficient = SimEngine.gui_get('rep_coef')
         rep_exponent = SimEngine.gui_get('rep_exponent')
         force = direction * (10**rep_coefficient) / 10 * dist**rep_exponent
         return force
     else:  # attraction
         dist = max(1, max(d, screen_distance_unit) / screen_distance_unit)
         att_exponent = SimEngine.gui_get('att_exponent')
         force = direction * dist**att_exponent
         # If the link is too short, push away instead of attracting.
         if d < screen_distance_unit:
             force = force * (-1)
         att_coefficient = SimEngine.gui_get('att_coef')
         return 10**(att_coefficient - 1) * force
示例#2
0
 def force_as_dxdy(pixel_a: Pixel_xy, pixel_b: Pixel_xy,
                   screen_distance_unit, repulsive):
     """
     Compute the force between pixel_a pixel and pixel_b and return it as a velocity: direction * force.
     """
     direction: Velocity = normalize_dxdy((
         pixel_a - pixel_b) if repulsive else (pixel_b - pixel_a))
     d = max(1, pixel_a.distance_to(pixel_b))  #, wrap=False))
     if repulsive:
         dist = max(1,
                    pixel_a.distance_to(pixel_b) /
                    screen_distance_unit)  #, wrap=False)
         rep_coefficient = gui_get(REP_COEFF)
         rep_exponent = gui_get(REP_EXPONENT)
         force = direction * (
             (10**rep_coefficient) / 10) * dist**rep_exponent
         return force
     else:  # attraction
         dist = max(1, max(d, screen_distance_unit) / screen_distance_unit)
         att_exponent = gui_get(ATT_EXPONENT)
         force = direction * dist**att_exponent
         # If the link is too short, push away instead of attracting.
         if d < screen_distance_unit:
             force = force * (-1)
         att_coefficient = gui_get(ATT_COEFF)
         final_force = force * 10**(att_coefficient - 1)
         return final_force