Skip to content
Snippets Groups Projects
Commit 8808ec3f authored by florian.burgener's avatar florian.burgener
Browse files

Add more constants

parent 2055cda6
Branches
No related tags found
No related merge requests found
#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);
}
}
......
......@@ -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;
......@@ -16,5 +16,6 @@ extern const int MAX_CHARGES;
extern const double K;
extern const double ELEMENTARY_CHARGE;
extern const double RADIUS_TRESHOLD;
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment