write("resistor");
TwoTerminal Rn = resistor((0,v), 0, normal, "$R_{normal}$", "30\ohm");
-dot("beg", Rn.beg, NW);
-dot("end", Rn.end, NE);
-dot("mid", Rn.mid, S);
+dot("beg", Rn.beg, NW, red);
+dot("end", Rn.end, NE, red);
+dot("mid", Rn.mid, S, red);
TwoTerminal Rvb = resistor((2u,v), 0, variable, "$R_{variable}$", "30\kohm");
v -= u;
dot("b", (9u/2,v-u/2), S);
wire((4u,v), (9u/2,v-u/2), rlsq, u/4);
v -= u;
+
+write("circuit");
+v -= u/2; // this circuit takes up more height than the previous lines.
+TwoTerminal Ccirc = capacitor((0,v), ang=90);
+TwoTerminal Rcirc = resistor(draw=false);
+Rcirc.centerto(Ccirc.beg, Ccirc.end);
+Rcirc.shift((u,0)); // gratuitous use of shift, but whatever...
+Rcirc.draw();
+// In the following, we assume the resistor is longer than the
+// capacitor. If that is not true, you can find the corners of the
+// circuit programatically and use those corners.
+wire(Rcirc.end, Ccirc.end, rlsq);
+wire(Rcirc.beg, Ccirc.beg, rlsq);
+pair Pcirc[] = {(Ccirc.beg.x,Rcirc.beg.y), (Ccirc.end.x,Rcirc.end.y),
+ Rcirc.end, Rcirc.beg};
+kirchhoff_loop(Pcirc);
+v -= u;
real linewd = 0.25mm;
-pen line = makepen(scale(0.5*linewd)*unitcircle);
-pen misc = makepen(scale(0.4*linewd)*unitcircle);
+pen line = linewidth(linewd);
+pen misc = linewidth(0.8*linewd);
+pen kirchhoff_pen = linewidth(10*linewd)+gray(0.7);
// Arrowhead definitions
add(pic, picL, (end-beg)/2);
}
+ /* Shift position by a */
+ void shift(pair a) {
+ this.beg += a;
+ this.end += a;
+ this.mid += a;
+ }
+
/* Rather than placing the element with a point and direction (beg,
* ang), center an element between the pairs a and b. The optional
* offset shifts the element in the direction rotated(90)*(b-a)
enddef;
*/
+
+// Loop symbols for Kirchhoff's rules.
+
+void kirchhoff_loop(picture pic=currentpicture, pair points[],
+ pen outline=kirchhoff_pen, real aspace=-1) {
+ // draw kirchhoff loop underneath currentpicture
+ picture newpic;
+ int i;
+ guide g;
+ pair a = points[0] - points[points.length-1]; // arrow distance
+ if (aspace < 0)
+ aspace = 3*linewidth(outline); // one dot diameter
+ real alength = max(0.5*length(a), length(a) - aspace - linewidth(outline)/2);
+ a = alength*unit(a);
+ pair astop = points[points.length-1] + a;
+ dot(newpic, points[0], scale(3)*outline);
+ for (int i=0; i < points.length; ++i)
+ g = g--points[i];
+ g = g -- astop;
+ draw(newpic, g, outline, Arrow(size=3*linewidth(outline)));
+ add(pic, newpic, above=false);
+}