From 0ea1da048092883f243cf25f35165097e151d6d2 Mon Sep 17 00:00:00 2001 From: Boris Stefanovic <owldev@bluewin.ch> Date: Mon, 9 May 2022 10:42:17 +0200 Subject: [PATCH] FIX: rewrite compute_total_normalized_e(...) --- src/field.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/field.c b/src/field.c index a5bc052..506a826 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 -- GitLab