diff --git a/main.cpp b/main.cpp index 0d22f7e..54ec1a3 100644 --- a/main.cpp +++ b/main.cpp @@ -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{ int row, col; double length, width; Sidewalk(int r, int c, double l, double w) : row(r), col(c), length(l), width(w) {} -}; - -struct Cell{ - // TODO: cell stores information such as next neighbor + /* X = obstacle + | X | + | X | + | | + | X | + |X | + */ }; // 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 - 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 -Vector2d get_direction(Vector2d curr_pos, Vector2d next_pos) { - double x, y, x1, x2, y1, y2; - - x1 = curr_pos.x; - x2 = next_pos.x; - y1 = curr_pos.y; - y2 = next_pos.y; - - x = (x2 - x1) / abs(x2 - x1); - y = (y2 - y1) / abs(y2 - y1); - - return Vector2d(x, y); +// return the direction between curr position and destination +// $\vectorarrow{e}_\alpha(t)$ +Vector2d get_direction(Pedestrian p) { + Vector2d diff = p.next_node - p.curr_pos; + double length = diff.norm(); + return (p.next_node - p.curr_pos) / length; } @@ -143,8 +154,12 @@ int main() { // Desired destination of pedestrian $n_p$ Vector2d r_0[n_p]; + // for each time frame for (int t = 0; t < n_iter; t++) { + // for each pedestrian for (int i = 0; i < n_p; i++) { + // update... + for (int itr = 0; itr < n_p; itr++) { F[i][itr].reset(); } @@ -156,7 +171,7 @@ int main() { // TODO: Update $\vec{v}_i^{t+1}$ - // TODO: pdate $\vec{r}_i^{t+1}$ + // TODO: Update $\vec{r}_i^{t+1}$ } }