diff --git a/src/Simulation.c b/src/Simulation.c index 3eb8282596cf8b3ff29a1706545e463b040c24b5..7f463beca39a9329a0a7a00e564641587aa1225b 100644 --- a/src/Simulation.c +++ b/src/Simulation.c @@ -1,5 +1,6 @@ #include "Simulation.h" +#include <math.h> #include <stdlib.h> #include "Charge.h" @@ -25,7 +26,7 @@ static Charge *generate_random_charges(Rectangle *universe, int *charges_length) Charge charge = generate_random_charge(); Vector2 position = charge.position; - double eps = (double)CHARGE_CIRCLE_RADIUS / SCREEN_WIDTH; + double eps = RADIUS_TRESHOLD; if (is_out_of_bounds(universe, vector2_add(position, vector2_init(0, -eps)))) { continue; } @@ -106,13 +107,10 @@ static bool compute_next_point(Simulation *simulation, int direction, Vector2 cu static void draw_field_line_with_direction(Simulation *simulation, Graphics *graphics, Vector2 starting_point, int direction) { Vector2 current_point = starting_point; - // Represents the acceptable distance between the last point and the charge, this distance is calculated with - // the radius of the charge display circle and the width of the window. - double eps = (double)CHARGE_CIRCLE_RADIUS / SCREEN_WIDTH; while (true) { Vector2 next_point; - if (!compute_next_point(simulation, direction, current_point, eps, &next_point)) { + if (!compute_next_point(simulation, direction, current_point, RADIUS_TRESHOLD, &next_point)) { break; } @@ -159,7 +157,9 @@ void simulation_draw(Simulation *simulation, Graphics *graphics) { double angle = 0; while (angle < 2 * M_PI) { angle += 2 * M_PI / 64; - Vector2 starting_point = vector2_add(position, vector2_init(cos(angle) * 0.1, sin(angle) * 0.1)); + double x = cos(angle) * RADIUS_TRESHOLD * 1.1; + double y = sin(angle) * RADIUS_TRESHOLD * 1.1; + Vector2 starting_point = vector2_add(position, vector2_init(x, y)); draw_field_line(simulation, graphics, starting_point); } } diff --git a/src/constants.c b/src/constants.c index 328cccaca13a202de96ff8c79b05591a336e19a4..03ffa9dabb328e0dbdc08bc07c631ae633858048 100644 --- a/src/constants.c +++ b/src/constants.c @@ -15,3 +15,6 @@ const int MAX_CHARGES = 5; const double K = 8.988e9; const double ELEMENTARY_CHARGE = 1.602e-19; +// Represents the acceptable distance between the last point and the charge, this distance is calculated with +// the radius of the charge display circle and the width of the window. +const double RADIUS_TRESHOLD = (double)CHARGE_CIRCLE_RADIUS / SCREEN_WIDTH; diff --git a/src/constants.h b/src/constants.h index 4f8d25e94932b6ddd232a4431d48f9bbaf5e46ec..d39f078c362791e1e2f74cd64a8d65699bb314c1 100644 --- a/src/constants.h +++ b/src/constants.h @@ -16,5 +16,6 @@ extern const int MAX_CHARGES; extern const double K; extern const double ELEMENTARY_CHARGE; +extern const double RADIUS_TRESHOLD; #endif