Skip to content

Commit 5da45ee

Browse files
committed
Fix cos_alpha computation in TTC formula
cos_alpha should be the dot product of the unit position difference (e_v) and the unit relative velocity (v_rel_hat). Previously, it was divided by (distance * v_rel_norm), which introduced a spurious 1/d factor since e_v was already a unit vector. Also rename v_rel_norm to delta_v_norm to clarify it is the magnitude of the actual relative velocity (used in the TTC denominator), not the norm of the unit vector.
1 parent d11587f commit 5da45ee

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

pedpy/methods/foo_calculator.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,14 @@ def compute_avoidance(
115115
shapely.get_coordinates(matrix.velocity)
116116
- shapely.get_coordinates(matrix.velocity_neighbor)
117117
)
118-
v_rel = delta_v / np.linalg.norm(delta_v, axis=1)[:, np.newaxis]
118+
delta_v_norm = np.linalg.norm(delta_v, axis=1)
119+
v_rel_hat = delta_v / delta_v_norm[:, np.newaxis]
119120

120-
v_rel_norm = np.linalg.norm(v_rel, axis=1)
121-
122-
dot_product = np.sum(
123-
np.array(np.array(e_v.tolist())) * np.array(np.array(v_rel.tolist())),
121+
cos_alpha = np.sum(
122+
np.array(e_v.tolist()) * np.array(v_rel_hat.tolist()),
124123
axis=1,
125124
)
126125

127-
cos_alpha = dot_product / (distance * v_rel_norm)
128-
129126
ttc = np.full(matrix.shape[0], np.inf)
130127

131128
capital_a = (cos_alpha**2 - 1) * distance**2 + radius**2
@@ -138,13 +135,13 @@ def compute_avoidance(
138135
valid_conditions = (
139136
(capital_a >= 0)
140137
& (-cos_alpha * distance - sqrt_a_safe >= 0)
141-
& (v_rel_norm != 0)
138+
& (delta_v_norm != 0)
142139
)
143140

144141
ttc[valid_conditions] = (
145142
-cos_alpha[valid_conditions] * distance[valid_conditions]
146143
- np.sqrt(capital_a[valid_conditions])
147-
) / v_rel_norm[valid_conditions]
144+
) / delta_v_norm[valid_conditions]
148145

149146
matrix[AVOIDANCE_COL] = tau_0 / ttc
150147

0 commit comments

Comments
 (0)