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

Stop line

parent 63bee7c6
Branches
Tags v1.0.0
No related merge requests found
......@@ -49,23 +49,30 @@ static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int n
vec2 pos_sum;
vec2 pos_next;
vec2 e;
bool stop = false;
double delta = compute_delta_x();
// Remplacer par une boucle qui s'arrête lorsqu'on atteint une charge
for (int i = 0; i < 100; i++)
uint32_t color = COLOR_YELLOW;
for (int i = 0; i < 100 && !stop; i++)
{
compute_total_normalized_e(charges, num_charges, pos, 0.01, &e);
pos_next.x = pos.x + delta * (e.x / vec2_normalize(e).x);
pos_next.y = pos.y + delta * (e.y / vec2_normalize(e).y);
for (int j = 0; j < num_charges && !stop; j++){
if(vec2_norm(vec2_sub(pos, charges[j].pos)) < dx / HEI){
color = COLOR_RED;
stop = true;
}
}
if(!stop){
compute_total_normalized_e(charges, num_charges, pos, 0.01, &e);
pos_next.x = pos.x + delta * (e.x / vec2_normalize(e).x);
pos_next.y = pos.y + delta * (e.y / vec2_normalize(e).y);
//printf("%f + %f * (%f / %f)\n", pos.x, delta, e.x, vec2_normalize(e).x);
//printf("%f %f\n", pos_next.x, pos_next.y);
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);
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);
//printf("%d %d\n", charge_1.column, charge_1.row);
//printf("%d %d\n\n", charge_2.column, charge_2.row);
gfx_draw_line(ctxt, coordinate_pos, coordinate_pos_next, COLOR_YELLOW);
pos = pos_next;
gfx_draw_line(ctxt, coordinate_pos, coordinate_pos_next, color);
pos = pos_next;
}
}
return EXIT_SUCCESS;
......@@ -109,7 +116,7 @@ void draw_everything(
srand(time(NULL));
draw_charges(ctxt, charges, num_charges, x0, x1, y0, y1);
for (int i = 0; i < num_lines; ++i) {
vec2 pos0 = vec2_create((double)rand() / RAND_MAX, (double)rand() / RAND_MAX);
vec2 pos0 = vec2_create(rand_one(), rand_one());
draw_field_line(ctxt, charges, num_charges, dx, pos0, x0, x1, y0, y1);
}
}
......@@ -7,14 +7,14 @@
#include "field.h"
#define NCHARGES 2
#define DX 0.0005
#define DX 25
#define NLINES 32
int main() {
charge_t charges[NCHARGES] = {
{.q=-0.25, .pos=vec2_create(0.25, 0.5)},
{.q=0.25, .pos=vec2_create(0.75, 0.5)},
charge_create(-0.25, vec2_create(0.25, 0.5)),
charge_create(0.25, vec2_create(0.75, 0.5))
};
struct gfx_context_t *ctxt = gfx_create("elec", WID, HEI);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment