angleL="$\rho$", stringL=Label("r", embed=Shift));
real len = abs(p.pivot.x-b.center().x);
-Spring s = Spring(pFrom=b.center()-(2u,0), pTo=b.center(), L="$k_1$");
+Spring s = Spring(
+ pFrom=b.center(), pTo=b.center()-(2u,0), L=Label("$k_1$", align=N));
s.draw();
-s = Spring(pFrom=b.center(), pTo=(p.pivot.x, b.center().y), L="$k_2$");
+s = Spring(
+ pFrom=b.center(), pTo=(p.pivot.x, b.center().y+0.5u),
+ L=Label("$k_2$", align=LeftSide, position=Relative(0.7)));
s.draw();
p.draw(drawVertical=true);
real unstretchedLength;
int nLoops;
pen outline;
- Label L;
+ Label label;
void operator init(pair pFrom=(0,0), pair pTo=(5mm,0), real k=1, real width=3mm, real dLength=1mm, real deadLength=3mm, real unstretchedLength=12mm, pen outline=currentpen, Label L="") {
this.pFrom = pFrom;
this.dLength = dLength;
this.unstretchedLength = unstretchedLength;
this.outline = outline;
- this.L = L;
+ this.label = L;
this.nLoops = floor((unstretchedLength-2*deadLength)/dLength);
if (this.nLoops == 0)
this.deadLength = (unstretchedLength-this.nLoops*dLength)/2;
}
- void draw(picture pic=currentpicture, bool rotateLabel=true) {
- picture picF;
- picture picL;
- label(picL, L);
- pair pLabelSize = 1.2 * (max(picL)-min(picL));
+ void draw(picture pic=currentpicture) {
pair pDiff = pTo - pFrom;
real working_dLength = (length(pDiff) - 2*deadLength) / nLoops;
}
loopStart = point(p, length(p));
p = p--(loopStart+(deadLength,0));
- p = rotate(degrees(pDiff)) * p;
-
- pair label_rotate=pDiff;
- if (rotateLabel == false)
- label_rotate=(1,0);
- draw(picF, p, outline);
- label(pic = picF,
- L = rotate(degrees(label_rotate)) * L,
- position = pDiff/2
- + unit(rotate(90)*pDiff) * (width + pLabelSize.y) / 2);
- add(pic, picF, pFrom);
+ p = shift(this.pFrom)*rotate(degrees(pDiff)) * p;
+ draw(pic, p, outline);
+ align a = this.label.align;
+ embed e = this.label.embed;
+ real m = labelmargin(this.label.p);
+ real scale = (m + this.width/2)/m;
+ if (this.label.align.is3D) {
+ this.label.align.dir3 *= scale;
+ } else {
+ this.label.align.dir *= scale;
+ }
+ if (this.label.embed == Rotate) {
+ this.label.embed = Rotate(this.pTo - this.pFrom);
+ }
+ label(pic=pic, L=this.label, g=this.pFrom -- this.pTo);
+ this.label.align = a;
+ this.label.embed = e;
}
}