Skip to content

Commit d11587f

Browse files
committed
Fix operator precedence bug in v_rel computation
Due to Python operator precedence, v_i - v_j / ||v_i - v_j|| was computing v_i - (v_j / ||v_i - v_j||) instead of the intended (v_i - v_j) / ||v_i - v_j||. Split into two steps to make the order of operations explicit.
1 parent 7f8a850 commit d11587f

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

pedpy/methods/foo_calculator.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,11 @@ def compute_avoidance(
111111
- shapely.get_coordinates(matrix.point_neighbor)
112112
) / distance[:, np.newaxis]
113113

114-
v_rel = shapely.get_coordinates(matrix.velocity) - shapely.get_coordinates(
115-
matrix.velocity_neighbor
116-
) / np.linalg.norm(
114+
delta_v = (
117115
shapely.get_coordinates(matrix.velocity)
118116
- shapely.get_coordinates(matrix.velocity_neighbor)
119117
)
118+
v_rel = delta_v / np.linalg.norm(delta_v, axis=1)[:, np.newaxis]
120119

121120
v_rel_norm = np.linalg.norm(v_rel, axis=1)
122121

0 commit comments

Comments
 (0)