updated w()

This commit is contained in:
lbaumberger
2026-03-27 09:38:40 +01:00
parent e905bc4a86
commit e8f5e94226
+33 -22
View File
@@ -1,10 +1,10 @@
#include <forces.h> #include <forces.h>
#include <math.h> #include <math.h>
// return the direction between curr position and destination // return the direction between curr position and destination
// $\vectorarrow{e}_\alpha(t)$ // $\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; Vector2d diff = p.desired_next_node - p.curr_pos;
double length = diff.norm(); double length = diff.norm();
return (p.desired_next_node - p.curr_pos) / length; 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 // return the direction between curr position and destination
// $\vectorarrow{e}_\alpha(t)$ // $\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; Vector2d diff = p.actual_next_node - p.curr_pos;
double length = diff.norm(); double length = diff.norm();
return (p.actual_next_node - p.curr_pos) / length; return (p.actual_next_node - p.curr_pos) / length;
} }
// double w(Vector2d e, Vector2d f) {
//
double w(Vector2d e, Vector2d f) { // if (e.dot(f) >= f.norm() * PHI_DEG) return 1.0;
// return C;
if (e.dot(f) >= f.norm() * PHI_DEG) return 1.0; //
// }
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; return C;
} }
// F_i is the current position resp. direction vector of pedestrian p in time i? // 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)$ // $\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; 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; double tau_inv = 1 / TAU;
p->F_i += (desired_velocity - actual_velocity) * tau_inv; 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})]$ // $\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) { void compute_repulsive_effects_from_pedestrians(Pedestrian *P, Pedestrian *p, int N)
{
double delta_t = 0.5; // assuming 0.5 seconds steps double delta_t = 0.5; // assuming 0.5 seconds steps
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++)
{
// TODO: add check for $\vectorarrow{e} * \vectorarrow{f} >= \Arrowvert \vectorarrow{f} \Arrowvert \cos(\phi) $ // TODO: add check for $\vectorarrow{e} * \vectorarrow{f} >= \Arrowvert \vectorarrow{f} \Arrowvert \cos(\phi) $
// only consider close pedestrians // only consider close pedestrians
if (P + i == p) continue; if (P + i == p)
if ((P[i].curr_pos - p->curr_pos).norm() < DISTANCE) { 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}$ // $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}$
// //
@@ -91,12 +103,14 @@ void compute_repulsive_effects_from_pedestrians(Pedestrian* P, Pedestrian* p, in
} }
// TODO: missing // 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; 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]; Vector2d obstacle = obstacles[i];
// TODO: find out the variables and parameters // TODO: find out the variables and parameters
// //
@@ -110,8 +124,5 @@ void compute_repulsive_effects_from_borders(Sidewalk& S, Pedestrian* p) {
double r_ab_norm = r_ab.norm(); 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);
} }
} }