implemented desired direction (1), added struct Pedestrian

This commit is contained in:
smail alijagic
2026-03-21 11:41:20 +01:00
parent df482ec7aa
commit c216fa777e
+35 -20
View File
@@ -26,14 +26,32 @@ struct Vector2d {
} }
}; };
struct Pedestrian {
Vector2d curr_pos; // $\vectorarrow{r}_\alpha(t)$
Vector2d next_pos; // $\vectorarrow{r}_\alpha(t+1)$ position, curr_pos is needed because when calculating the force on pedestrian j, we need the old pos, not the updated
Vector2d curr_vel, next_vel; // velocity
Vector2d destination; // $\vectorarrow{r}^0_\alpha$
Vector2d next_node; // $\vectorarrow{r}^k_\alpha$
double v0; // speed in m/s e.g. 1.34
double vMax; // vMax = v0 * 1.3
// direction Vector2d e = (dest - curr.position).norm() --> calculate on the fly or part of struct?
void update() { curr_pos = next_pos; }
};
// initialize map
struct Sidewalk{ struct Sidewalk{
int row, col; int row, col;
double length, width; double length, width;
Sidewalk(int r, int c, double l, double w) : row(r), col(c), length(l), width(w) {} Sidewalk(int r, int c, double l, double w) : row(r), col(c), length(l), width(w) {}
}; /* X = obstacle
| X |
struct Cell{ | X |
// TODO: cell stores information such as next neighbor | |
| X |
|X |
*/
}; };
// Numer of pedestrians // Numer of pedestrians
@@ -72,24 +90,17 @@ void compute_acceleration_term(Vector2d *F_i, Vector2d curr, Vector2d next) {
} }
Vector2d get_next_node(Vector2d curr_pos, Vector2d map[]) { Vector2d get_next_node(Pedestrian p, Vector2d map[]) {
// dummy element // dummy element
return Vector2d(curr_pos.x + 1.0, curr_pos.y + 1.0); return Vector2d(p.curr_pos.x + 1.0, p.curr_pos.y + 1.0);
} }
// return the direction between two nodes along the shortest path // return the direction between curr position and destination
Vector2d get_direction(Vector2d curr_pos, Vector2d next_pos) { // $\vectorarrow{e}_\alpha(t)$
double x, y, x1, x2, y1, y2; Vector2d get_direction(Pedestrian p) {
Vector2d diff = p.next_node - p.curr_pos;
x1 = curr_pos.x; double length = diff.norm();
x2 = next_pos.x; return (p.next_node - p.curr_pos) / length;
y1 = curr_pos.y;
y2 = next_pos.y;
x = (x2 - x1) / abs(x2 - x1);
y = (y2 - y1) / abs(y2 - y1);
return Vector2d(x, y);
} }
@@ -143,8 +154,12 @@ int main() {
// Desired destination of pedestrian $n_p$ // Desired destination of pedestrian $n_p$
Vector2d r_0[n_p]; Vector2d r_0[n_p];
// for each time frame
for (int t = 0; t < n_iter; t++) { for (int t = 0; t < n_iter; t++) {
// for each pedestrian
for (int i = 0; i < n_p; i++) { for (int i = 0; i < n_p; i++) {
// update...
for (int itr = 0; itr < n_p; itr++) { for (int itr = 0; itr < n_p; itr++) {
F[i][itr].reset(); F[i][itr].reset();
} }
@@ -156,7 +171,7 @@ int main() {
// TODO: Update $\vec{v}_i^{t+1}$ // TODO: Update $\vec{v}_i^{t+1}$
// TODO: pdate $\vec{r}_i^{t+1}$ // TODO: Update $\vec{r}_i^{t+1}$
} }
} }