diff --git a/forces.cpp b/forces.cpp index a80f221..66264d1 100644 --- a/forces.cpp +++ b/forces.cpp @@ -1,10 +1,10 @@ #include #include - // return the direction between curr position and destination // $\vectorarrow{e}_\alpha(t)$ -Vector2d get_desired_direction(Pedestrian& p) { +Vector2d get_desired_direction(Pedestrian &p) +{ Vector2d diff = p.desired_next_node - p.curr_pos; double length = diff.norm(); return (p.desired_next_node - p.curr_pos) / length; @@ -12,27 +12,37 @@ Vector2d get_desired_direction(Pedestrian& p) { // return the direction between curr position and destination // $\vectorarrow{e}_\alpha(t)$ -Vector2d get_actual_direction(Pedestrian& p) { +Vector2d get_actual_direction(Pedestrian &p) +{ Vector2d diff = p.actual_next_node - p.curr_pos; double length = diff.norm(); return (p.actual_next_node - p.curr_pos) / length; } - - -double w(Vector2d e, Vector2d f) { - - if (e.dot(f) >= f.norm() * PHI_DEG) return 1.0; +// double w(Vector2d e, Vector2d f) { +// +// if (e.dot(f) >= f.norm() * PHI_DEG) return 1.0; +// return C; +// +// } +double w(Vector2d e, Vector2d f) +{ + // The w() function should check if the angle between the desired direction e and the force f is within the field of view. + // Per equation (7), the condition is: + // e · f ≥ ||f|| * cos(phi) + // where phi = 100° (half of the 200° field of view (PHI_DEG)). + const double phi = (PHI_DEG / 2.0) * M_PI / 180.0; // half-angle in radians + if (e.dot(f) >= f.norm() * cos(phi)) + return 1.0; return C; - } - // F_i is the current position resp. direction vector of pedestrian p in time i? // // $\vectorarrow{F}_\alpha(\vectorarrow{v}_\alpha, v^0_\alpha \vectorarrow{e}_\alpha) \vectorarrow{e}_\alpha(t) = \frac{1}{\tau_\alpha}(v^0_\alpha \vectorarrow{e}_\alpha - \vectorarrow{v}_\alpha)$ // -void compute_acceleration_term(Pedestrian *p) { +void compute_acceleration_term(Pedestrian *p) +{ Vector2d desired_velocity = get_desired_direction(*p) * p->desired_v0; @@ -43,22 +53,24 @@ void compute_acceleration_term(Pedestrian *p) { double tau_inv = 1 / TAU; p->F_i += (desired_velocity - actual_velocity) * tau_inv; - } - // $\vectorarrow{f}_{\alpha \beta}(\vectorarrow{r}_{\alpha \beta}) = -\gradient_{\vectorarrow{r}_{\alpha \beta}} V_{\alpha \beta}[b(\vectorarrow{r}_{\alpha \beta})]$ -void compute_repulsive_effects_from_pedestrians(Pedestrian* P, Pedestrian* p, int N) { - double delta_t = 0.5; // assuming 0.5 seconds steps - for (int i = 0; i < N; i++) { +void compute_repulsive_effects_from_pedestrians(Pedestrian *P, Pedestrian *p, int N) +{ + double delta_t = 0.5; // assuming 0.5 seconds steps + for (int i = 0; i < N; i++) + { // TODO: add check for $\vectorarrow{e} * \vectorarrow{f} >= \Arrowvert \vectorarrow{f} \Arrowvert \cos(\phi) $ // only consider close pedestrians - if (P + i == p) continue; - if ((P[i].curr_pos - p->curr_pos).norm() < DISTANCE) { + if (P + i == p) + continue; + if ((P[i].curr_pos - p->curr_pos).norm() < DISTANCE) + { // // $2b = \sqrt{(\Arrowvert \vectorarrow{r}_{\alpha \beta} \Arrowvert + \Arrowvert \vectorarrow{r}_{\alpha \beta} - v_\beta \Delta t \vectorarrow{e}_\beta \Arrowvert)^2 - (v_\beta \Delta t)^2}$ // - // $\Arrowvert \vectorarrow{r}_{\alpha \beta} \Arrowvert$ + // $\Arrowvert \vectorarrow{r}_{\alpha \beta} \Arrowvert$ Vector2d r_ab = p->curr_pos - P[i].curr_pos; double r_ab_norm = (p->curr_pos - P[i].curr_pos).norm(); @@ -71,7 +83,7 @@ void compute_repulsive_effects_from_pedestrians(Pedestrian* P, Pedestrian* p, in double v_beta_delta_t = P[i].actual_v0 * delta_t; double b = sqrt((r_ab_norm + r_ab_something_norm) * (r_ab_norm + r_ab_something_norm) - (v_beta_delta_t) * (v_beta_delta_t)) / 2; - + // // $\vectorarrow{f}_{\alpha \beta}(\vectorarrow{r}_{\alpha \beta}) = \frac{V^0_{\alpha \beta}}{\sigma}e^{-b / \sigma} \grad_{\vectorarrow{r}_{\alpha \beta}}b$ // @@ -80,23 +92,25 @@ void compute_repulsive_effects_from_pedestrians(Pedestrian* P, Pedestrian* p, in // // $\grad_{\vectorarrow{r}_{\alpha \beta}} = \frac{(\Arrowvert \vectorarrow{r}_{\alpha \beta} \Arrowvert + \Arrowvert \vectorarrow{r}_{\alpha \beta} - v_\beta \Delta t \vectorarrow{e}_\beta \Arrowvert) (\frac{\vectorarrow{r}_{\alpha \beta}}{\Arrowvert \vectorarrow{r}_{\alpha \beta} \Arrowvert} + \frac{\vectorarrow{r}_{\alpha \beta} - v_\beta \Delta t \vectorarrow{e}_\beta}{\Arrowvert \vectorarrow{r}_{\alpha \beta} - v_\beta \Delta t \vectorarrow{e}_\beta \Arrowvert})}{4b}$ // - Vector2d delta_r_alpha_beta = ( ( (r_ab / r_ab_norm) + (r_ab_something / r_ab_something_norm) ) * (r_ab_norm + r_ab_something_norm) ) / (4 * b); + Vector2d delta_r_alpha_beta = (((r_ab / r_ab_norm) + (r_ab_something / r_ab_something_norm)) * (r_ab_norm + r_ab_something_norm)) / (4 * b); // $\vectorarrow{f}_{\alpha \beta}$ Vector2d f_alpha_beta_r_alpha_beta = delta_r_alpha_beta * ((V0_AB / SIGMA) * (exp(-b / SIGMA))); - + p->F_i += f_alpha_beta_r_alpha_beta * w(get_desired_direction(*p), f_alpha_beta_r_alpha_beta * -1); } } } // TODO: missing -void compute_repulsive_effects_from_borders(Sidewalk& S, Pedestrian* p) { - - Vector2d* obstacles = S.obstacles; +void compute_repulsive_effects_from_borders(Sidewalk &S, Pedestrian *p) +{ + + Vector2d *obstacles = S.obstacles; int n_obs = S.n_obstacles; - for (int i = 0; i < n_obs; i++) { + for (int i = 0; i < n_obs; i++) + { Vector2d obstacle = obstacles[i]; // TODO: find out the variables and parameters // @@ -109,9 +123,6 @@ void compute_repulsive_effects_from_borders(Sidewalk& S, Pedestrian* p) { // $\Arrowvert \vectorarrow{r}_{\alpha B} \Arrowvert$ double r_ab_norm = r_ab.norm(); - p->F_i += * w(get_desired_direction(*p), * -1); - + p->F_i += *w(get_desired_direction(*p), *-1); } - } -