real u = 1cm;
Charge a = pCharge(center=(0.5u,2u));
-Charge b = aCharge(center=(0,0), q=1);
-Charge c = nCharge(center=(-3u,0), q=-3);
+Charge b = aCharge(center=(0,-0.5u), q=1);
+Charge c = nCharge(center=(-3u,-0.5u), q=-3);
Charge cs[] = {a,b,c};
Distance dab = Distance(b.center(), a.center(), scale=u, L="$r_1$");
Distance dbc = Distance(c.center(), b.center(), scale=u, L="$r_2$");
for (int i=0; i<as.length; i+=1)
as[i].draw();
+CoulombEFields((-1.5u, 1.4u), c=cs, scale=2u, unit=u/2);
//Vector Fba = CoulombForce(b,a, scale=2u, unit=u);
//Fba.draw();
CoulombForces(c=cs, scale=2u, unit=u);
return v;
}
+// ------------------ Electric fields --------------------
+
+// Electric field at a due to b
+Vector CoulombEField(pair a, Charge b, Label L="", real scale=1mm,
+ real unit=1mm)
+{
+ pair r = a - b.center();
+ real mag, dir;
+ mag = (abs(b.q)*(scale/length(r))^2)*unit;
+ dir = degrees(r);
+ if (b.q < 0) {
+ dir += 180;
+ }
+ Vector v = EField(center=a, mag=mag, dir=dir, L=L);
+ return v;
+}
+
+void CoulombEFields(pair a, Charge c[], real scale=1mm, real unit=1mm)
+{
+ Vector E;
+ string s;
+ for (int i=0; i<c.length; i+=1) {
+ s = "$E_{" + format("%d", i+1) + "}$";
+ E = CoulombEField(a, c[i], L=s, scale=scale, unit=unit);
+ E.draw();
+ }
+}
+
// ---------------------- Forces -------------------------
// Force of a on b