diff --git a/src/field.c b/src/field.c index a5bc052cd60473851c30076b54ace12d6b342d84..506a8269c888d55729b2f41b934c0686d33c2f84 100644 --- a/src/field.c +++ b/src/field.c @@ -21,9 +21,17 @@ bool compute_e(charge_t c, vec2 p, double eps, vec2 *e) { // Compute the normalized sum of Ei*qiP/norm(qiP) // Return false if for some qiP, norm(qiP) < eps bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p, double eps, vec2 *e) { - return EXIT_SUCCESS; + *e = vec2_create_zero(); + vec2 ei = vec2_create_zero(); + for (int i = 0; i < num_charges; ++i) { + if (!compute_e(charges[i], p, eps, &ei)) return false; + *e = vec2_add(*e, ei); + } + *e = vec2_normalize(*e); + return true; } + // Compute and then draw all the points belonging to a field line, // starting from pos0. // Returns false if pos0 is not a valid position