updated w()

This commit is contained in:
lbaumberger
2026-03-27 09:38:40 +01:00
parent e905bc4a86
commit e8f5e94226
+37 -26
View File
@@ -1,10 +1,10 @@
#include <forces.h>
#include <math.h>
// 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,18 +53,20 @@ 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}$
//
@@ -80,7 +92,7 @@ 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)));
@@ -91,12 +103,14 @@ void compute_repulsive_effects_from_pedestrians(Pedestrian* P, Pedestrian* p, in
}
// TODO: missing
void compute_repulsive_effects_from_borders(Sidewalk& S, Pedestrian* p) {
void compute_repulsive_effects_from_borders(Sidewalk &S, Pedestrian *p)
{
Vector2d* obstacles = S.obstacles;
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);
}
}