Charge b = aCharge(center=(0,-0.5u), q=1);
Charge c = nCharge(center=(-3u,-0.5u), q=-3);
Charge cs[] = {a,b,c};
+string subscripts[] = {"a"};
Distance dab = Distance(b.center(), a.center(), scale=u, L="$r_1$");
Distance dbc = Distance(c.center(), b.center(), scale=u, L="$r_2$");
Distance ds[] = {dab};
for (int i=0; i<as.length; i+=1)
as[i].draw();
-CoulombEFields((-0.5u, 1.2u), c=cs, scale=2u, unit=u/2);
+CoulombEFields((-0.5u, 1.2u), c=cs, subscripts=subscripts, scale=2u, unit=u/2);
//Vector Fba = CoulombForce(b,a, scale=2u, unit=u);
//Fba.draw();
-CoulombForces(c=cs, scale=2u, unit=u);
+CoulombForces(c=cs, subscripts=subscripts, scale=2u, unit=u);
Charge a = aCharge(center=(-2u, 2u), q=0);
a.draw();
return v;
}
-void CoulombEFields(pair a, Charge c[], real scale=1mm, real unit=1mm)
+void CoulombEFields(pair a, Charge c[], string subscripts[]={}, real scale=1mm,
+ real unit=1mm)
{
Vector E;
- string s;
+ string s, sub;
for (int i=0; i<c.length; i+=1) {
- s = "$E_{" + format("%d", i+1) + "}$";
+ if (i < subscripts.length) {
+ sub = subscripts[i];
+ } else {
+ sub = format("%d", i+1);
+ }
+ s = "$E_{" + sub + "}$";
E = CoulombEField(
a, c[i], L=Label(s, position=EndPoint, align=LeftSide),
scale=scale, unit=unit);
return v;
}
-void CoulombForces(Charge c[], real scale=1mm, real unit=1mm)
+void CoulombForces(Charge c[], string subscripts[]={}, real scale=1mm,
+ real unit=1mm)
{
Vector F;
- string s;
+ string s, subi, subj;
for (int i=0; i<c.length; i+=1) {
+ if (i < subscripts.length) {
+ subi = subscripts[i];
+ } else {
+ subi = format("%d", i+1);
+ }
for(int j=0; j<c.length; j+=1) {
if (i==j) continue;
- s = "$F_{" + format("%d", i+1) + "," + format("%d", j+1) + "}$";
+ if (j < subscripts.length) {
+ subj = subscripts[j];
+ } else {
+ subj = format("%d", j+1);
+ }
+ s = "$F_{" + subi + "," + subj + "}$";
F = CoulombForce(
c[i], c[j], L=Label(s, position=EndPoint, align=LeftSide),
scale=scale, unit=unit);