Skip to content
Snippets Groups Projects
Commit 21f81f18 authored by JM's avatar JM
Browse files

draw_field_line fonctionnel mais pas beau et besoin d'optimisation

parent 658fffb2
Branches
No related tags found
No related merge requests found
...@@ -59,8 +59,9 @@ static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int n ...@@ -59,8 +59,9 @@ static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int n
vec2 pos_next; vec2 pos_next;
vec2 e; vec2 e;
bool stop = false; bool stop = false;
double delta = compute_delta_x(); double delta = compute_delta_x() * 5;
for (int i = 0; i < 300 && !stop; i++) int max_for = 300;
for (int i = 0; i < max_for && !stop; i++)
{ {
for (int j = 0; j < num_charges && !stop; j++){ for (int j = 0; j < num_charges && !stop; j++){
if(vec2_norm(vec2_sub(pos, charges[j].pos)) < dx / HEI){ if(vec2_norm(vec2_sub(pos, charges[j].pos)) < dx / HEI){
...@@ -79,12 +80,36 @@ static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int n ...@@ -79,12 +80,36 @@ static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int n
gfx_draw_line(ctxt, coordinate_pos, coordinate_pos_next, COLOR_YELLOW); gfx_draw_line(ctxt, coordinate_pos, coordinate_pos_next, COLOR_YELLOW);
pos = pos_next; pos = pos_next;
printf("F\n"); if(!is_in_screen(coordinate_pos))
//if(!is_in_screen(coordinate_pos)) stop = false;
// stop = false;
} }
} }
pos = vec2_create(pos0.x, pos0.y);
stop = false;
for (int i = 0; i < max_for && !stop; i++)
{
for (int j = 0; j < num_charges && !stop; j++){
if(vec2_norm(vec2_sub(pos, charges[j].pos)) < dx / HEI){
stop = true;
}
}
if(!stop){
compute_total_normalized_e(charges, num_charges, pos, 0.01, &e);
double norm_e = vec2_norm(e);
pos_next.x = pos.x - delta * (e.x / norm_e);
pos_next.y = pos.y - delta * (e.y / norm_e);
coordinates_t coordinate_pos = position_to_coordinates(WID, HEI, x0, x1, y0, y1, pos);
coordinates_t coordinate_pos_next = position_to_coordinates(WID, HEI, x0, x1, y0, y1, pos_next);
gfx_draw_line(ctxt, coordinate_pos, coordinate_pos_next, COLOR_YELLOW);
pos = pos_next;
if(!is_in_screen(coordinate_pos))
stop = false;
}
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#define NCHARGES 2 #define NCHARGES 2
#define DX 25 #define DX 25
#define NLINES 32 #define NLINES 5
int main() { int main() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment