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

Modification génération ligne

parent ced5490b
Branches
No related tags found
No related merge requests found
......@@ -9,7 +9,6 @@
#define SIGN_SIZE 10
#define CHARGE_R 25
// Compute E*qP/norm(qP)
// Return false if norm(qP) < eps
/// qP = vectoriel(P-q)
......@@ -35,6 +34,11 @@ bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p, doub
return true;
}
double compute_delta_x(){
double result = pow(WID, 2) + pow(HEI, 2);
result = sqrt(result);
return 1 / result;
}
// Compute and then draw all the points belonging to a field line,
// starting from pos0.
......@@ -43,12 +47,27 @@ bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p, doub
static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int num_charges, double dx, vec2 pos0, double x0, double x1, double y0, double y1) {
vec2 pos = vec2_create(pos0.x, pos0.y);
vec2 pos_sum;
for (int i = 0; i < num_charges; i++)
vec2 pos_next;
vec2 e;
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++)
{
//compute_e(charges[i], ..., &pos_sum);
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);
//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;
}
//vec2 pos_next =
return EXIT_SUCCESS;
}
......@@ -87,9 +106,10 @@ void draw_everything(
double dx,
double x0, double x1,
double y0, double y1) {
srand(time(NULL));
draw_charges(ctxt, charges, num_charges, x0, x1, y0, y1);
for (int i = 0; i < num_lines; ++i) {
vec2 pos0 = vec2_normalize(vec2_create(rand(), rand()));
vec2 pos0 = vec2_create((double)rand() / RAND_MAX, (double)rand() / RAND_MAX);
draw_field_line(ctxt, charges, num_charges, dx, pos0, x0, x1, y0, y1);
}
}
......@@ -12,7 +12,6 @@
int main() {
srand(time(NULL));
charge_t charges[NCHARGES] = {
{.q=-0.25, .pos=vec2_create(0.25, 0.5)},
{.q=0.25, .pos=vec2_create(0.75, 0.5)},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment