75 lines
1.9 KiB
C++
75 lines
1.9 KiB
C++
#include "forces.hpp"
|
|
#include <math.h>
|
|
|
|
double w(Vector2d e, Vector2d f) {
|
|
if (e.dot(f) >= f.norm() * cos_phi)
|
|
return 1.0;
|
|
else
|
|
return c;
|
|
}
|
|
|
|
double g(double v_max_alpha, double w_alpha_norm) {
|
|
if (w_alpha_norm <= v_max_alpha) {
|
|
return 1;
|
|
}
|
|
return v_max_alpha / w_alpha_norm;
|
|
}
|
|
|
|
void compute_acceleration_term(Pedestrian *p) {
|
|
Vector2d desired_velocity = p->e * p->desired_v0;
|
|
Vector2d actual_velocity = p->curr_vel;
|
|
p->f_i += (desired_velocity - actual_velocity) / tau_alpha;
|
|
}
|
|
|
|
void compute_repulsive_effects_from_pedestrians(Pedestrian *pedestrians, Pedestrian *p, int N) {
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
|
|
if (pedestrians + i == p)
|
|
continue;
|
|
|
|
// # Optional: Do not consider far away pedestrians from current pedestrian
|
|
// # Might get better speed up, remove if not
|
|
// if ((pedestrians[i].curr_pos - p->curr_pos).norm() > DISTANCE) {
|
|
// continue;
|
|
// }
|
|
|
|
Vector2d r_ab = p->curr_pos - pedestrians[i].curr_pos;
|
|
|
|
double r_ab_norm = r_ab.norm();
|
|
|
|
Vector2d e_b = pedestrians[i].e;
|
|
|
|
double s_b = pedestrians[i].desired_v0 * delta_t;
|
|
|
|
Vector2d r_ab2 = r_ab - (e_b * s_b);
|
|
|
|
double r_ab2_norm = r_ab2.norm();
|
|
|
|
double b = sqrt(pow(r_ab_norm + r_ab2_norm, 2) - pow(s_b, 2)) / 2;
|
|
|
|
Vector2d b_grad = (r_ab / r_ab_norm + r_ab2 / r_ab2_norm) * (r_ab_norm + r_ab2_norm) / (4 * b);
|
|
|
|
Vector2d f_ped = b_grad * ((V0_AB / SIGMA) * (exp(-b / SIGMA)));
|
|
|
|
p->f_i += f_ped * w(p->e, f_ped * -1);
|
|
}
|
|
}
|
|
|
|
void compute_repulsive_effects_from_borders(Board &board, Pedestrian *p) {
|
|
|
|
Obstacle *obstacles = board.obstacles;
|
|
int n_borders = board.n_obstacles;
|
|
|
|
for (int i = 0; i < n_borders; i++) {
|
|
|
|
Obstacle obstacle = obstacles[i];
|
|
|
|
Vector2d r_aB = p->curr_pos - obstacle.find_nearest_obstacle_point(p->curr_pos);
|
|
|
|
Vector2d f_obst = (r_aB / r_aB.norm()) * (U0_AB / R) * std::exp(-r_aB.norm() / R);
|
|
|
|
p->f_i += f_obst;
|
|
}
|
|
}
|