added arrows

This commit is contained in:
smail alijagic
2026-04-27 16:42:30 +02:00
parent cc1808ee3c
commit 40eb9a963f
9 changed files with 98055 additions and 1000039 deletions
+11 -9
View File
@@ -33,7 +33,7 @@ Pedestrian *init_pedestrians(int n_p) {
for (int i = 0; i < n_p / 2; i++) {
double y = y_gen(gen);
Vector2d start_pos = Vector2d(x_gen(gen), y);
Vector2d destination = Vector2d(BOARD_LENGTH + 300, BOARD_WIDTH / 2);
Vector2d destination = Vector2d(BOARD_LENGTH + 30, BOARD_WIDTH / 2);
// double desired_v0 = velocity_gen(gen);
double desired_v0;
do {
@@ -46,7 +46,7 @@ Pedestrian *init_pedestrians(int n_p) {
for (int i = n_p / 2; i < n_p; i++) {
double y = y_gen(gen);
Vector2d start_pos = Vector2d(x_gen(gen), y);
Vector2d destination = Vector2d(-300, BOARD_WIDTH / 2);
Vector2d destination = Vector2d(-30, BOARD_WIDTH / 2);
// double desired_v0 = velocity_gen(gen);
double desired_v0;
do {
@@ -70,7 +70,7 @@ int main(int argc, const char *argv[]) {
const int dump_interval = 50; // dump every 5 iterations -> 20 fps (since dt = 0.01)
const char *dump_path = (argc >= 4) ? argv[3] : nullptr;
std::vector<std::tuple<int, int, double, double, int>> samples; // t, id, x, y, color
std::vector<std::tuple<int, int, double, double, double, double, int>> samples; // t, id, x, y, e.x, e.y, color
if (dump_path)
samples.reserve((size_t)n_iter / dump_interval * n_p);
@@ -119,7 +119,7 @@ int main(int argc, const char *argv[]) {
// # 4 flops = 2 ADDs, 2 MULTs
//
// $\vec{r}_i^{t+1} += \vec{r}^t_i + v^t_idt$
// $\vec{r}_i^{t+1} = \vec{r}^t_i + v^t_idt$
//
p.curr_pos = p.curr_pos + p.curr_vel * dt;
@@ -137,11 +137,13 @@ int main(int argc, const char *argv[]) {
}
// # 10 flops = 5 ADDs, 2 DIVs, 1 SQRT, 2 MULTs
p.e = (p.destination - p.curr_pos) / (p.destination - p.curr_pos).norm();
//p.e = (p.destination - p.curr_pos) / (p.destination - p.curr_pos).norm();
//p.e = (p.curr_vel - p.destination) / (p.curr_vel - p.destination).norm();
p.e = (p.destination - (p.curr_vel / p.curr_vel.norm())) / (p.destination - (p.curr_vel / p.curr_vel.norm())).norm();
// if we have a dump path/file we wanna save the data for visualisation
if (dump_path && (t % dump_interval == 0)) {
samples.emplace_back(t, i, p.curr_pos.x, p.curr_pos.y, p.color);
samples.emplace_back(t, i, p.curr_pos.x, p.curr_pos.y, p.e.x, p.e.y, p.color);
}
}
}
@@ -164,9 +166,9 @@ int main(int argc, const char *argv[]) {
// now we wanna save the data to a csv
if (dump_path) {
std::ofstream out(dump_path);
out << "time,id,x,y,color\n";
for (auto &[t, id, x, y, c] : samples) {
out << t << ',' << id << ',' << x << ',' << y << ',' << c << '\n';
out << "time,id,x,y,p.e.x,p.e.y,color\n";
for (auto &[t, id, x, y, e_x, e_y, c] : samples) {
out << t << ',' << id << ',' << x << ',' << y << ',' << e_x << ',' << e_y << ',' << c << '\n';
}
}