for (int i=0; i<vs.length; i+=1)
vs[i].draw();
-Pendulum p = makePendulum(pivot=(3.5u,-3u), mass=b, length=4u, angleDeg=-20,
- angleL="$\rho$", stringL="r");
+Pendulum p = makePendulum(
+ pivot=(3.5u,-3u), mass=b, length=4u, angleDeg=-20,
+ 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$");
pair pFrom;
pair pTo;
pen outline;
- Label L;
-
+ Label label;
+
void operator init(pair pFrom=(0,0), pair pTo=(5mm,0), pen outline=currentpen, Label L="") {
this.pFrom = pFrom;
this.pTo = pTo;
this.outline = outline;
- this.L = L;
+ this.label = L;
}
-
- void draw(picture pic=currentpicture, bool rotateLabel=true) {
- picture picF;
- picture picL;
- label(picL, L);
- pair pLabelSize = 1.2 * (max(picL)-min(picL));
- pair pDiff = pTo - pFrom;
- path p = (0,0)--pDiff;
- 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) * pLabelSize.y / 2);
- add(pic, picF, pFrom);
+
+ void draw(picture pic=currentpicture) {
+ path p = this.pFrom--this.pTo;
+ draw(pic, p, outline);
+ embed e = this.label.embed;
+ if (this.label.embed == Rotate) {
+ this.label.embed = Rotate(this.pFrom - this.pTo);
+ }
+ label(pic=pic, L=this.label, g=p);
+ this.label.embed = e;
}
}
Mass mass;
Angle angle;
Wire str;
-
+
void operator init(pair pivot=(0,0), Mass mass=Mass()) {
this.pivot = pivot;
this.mass = mass;
this.angle = Angle(mass.center(), pivot, pivot-(0,1));
this.str = Wire(pivot, mass.center());
}
-
+
void draw(picture pic=currentpicture, bool drawVertical=false) {
- str.draw(pic=pic, rotateLabel=false);
+ str.draw(pic=pic);
if (drawVertical == true) {
pair final = pivot + realmult((0,0.5),(mass.center()-pivot));
draw(pic=pic, pivot--final, p=currentpen+dashed);
mass.set_center(pivot + length*dir(angleDeg-90));
Pendulum p = Pendulum(pivot=pivot, mass=mass);
p.angle.label = angleL;
- p.str.L = stringL;
+ p.str.label = stringL;
return p;
}