Mass b = Mass(center=(2u,1u), Label("$m_b$", align=N));
Mass c = Mass(center=(1u,-2u), Label("$m_c$", align=E));
Mass ms[] = {a,b, c};
-Distance dab = Distance(a.center(), b.center(), scale=u, L="$r_{ab}$");
+Distance dab = Distance(b.center(), a.center(), scale=u,
+ L=Label("$r_{ab}$", embed=Shift));
Distance dac = Distance(a.center(), c.center(), scale=u, L="$r_{ac}$");
Distance ds[] = {dab, dac};
Angle bac1 = Angle(
b.center(), a.center(), c.center(), radius=.7u, fill=red, L="$\theta_T'$");
Angle bac2 = Angle(
b.center(), a.center(), c.center(), radius=-.5u, L="$\theta_T$");
-Angle as[] = {bac1, bac2};
+Angle bac3 = Angle(
+ b.center(), a.center(), c.center(), radius=1.5u,
+ L=Label("$\theta_T''$", position=Relative(0.3)));
+Angle as[] = {bac1, bac2, bac3};
Vector vs[];
}
void draw_label(picture pic=currentpicture, Label L=null) {
- picture picL;
align a;
if (L == null) {
L = this.label;
real offset;
real scale;
pen outline;
- Label L;
+ Label label;
void operator init(pair pFrom=(0,0), pair pTo=(5mm,0), real offset=0, real scale=5mm, pen outline=currentpen, Label L="") {
this.pFrom = pFrom;
this.offset = offset;
this.scale = scale;
this.outline = outline;
- this.L = L;
+ this.label = L;
}
-
- void draw(picture pic=currentpicture, bool rotateLabel=true,
- real labelangle=90, real labeloffset=-1) {
- picture picF;
- pair pDiff = pTo - pFrom;
- if (labeloffset == -1) {
- picture picL;
- label(picL, L);
- pair pLabelSize = 1.2 * (max(picL)-min(picL));
- labeloffset = pLabelSize.y/2;
+
+ void draw(picture pic=currentpicture) {
+ pair o = this.offset*unit(rotate(-90)*(this.pTo - this.pFrom));
+ path p = (this.pFrom+o) -- (this.pTo+o);
+ draw(pic, p, outline, Arrows);
+ embed e = this.label.embed;
+ if (this.label.embed == Rotate) {
+ this.label.embed = Rotate(this.pFrom - this.pTo);
}
- path p = (0,0)--pDiff;
- pair label_rotate=pDiff;
- if (rotateLabel == false)
- label_rotate=(1,0);
- draw(picF, p, outline, Arrows);
- label(pic = picF,
- L = rotate(degrees(label_rotate)) * L,
- position = pDiff/2
- + unit(rotate(labelangle)*pDiff) * labeloffset);
- //label(pic=picF, L = rotate(degrees(label_rotate)) format("%g", pDiff/scale), position = TODO);
- add(pic, picF, pFrom+offset*unit(rotate(-90)*pDiff));
+ label(pic=pic, L=this.label, g=p);
+ this.label.embed = e;
}
}
real radius; // radius < 0 for exterior angles.
pen outline;
pen fill;
- Label L;
+ Label label;
void operator init(pair B, pair A, pair C, real radius=5mm, pen outline=currentpen, pen fill=invisible, Label L="") {
this.B = B;
this.radius = radius;
this.outline = outline;
this.fill = fill;
- this.L = L;
+ this.label = L;
}
- void draw(picture pic=currentpicture, bool rotateLabel=false,
- real labelOffsetAdjustment=0) {
+ void draw(picture pic=currentpicture) {
picture picF;
- picture picL;
bool direction;
- label(picL, L);
- pair pLabelSize = 1.2 * (max(picL)-min(picL));
real ccw_angle = degrees(C-A)-degrees(B-A);
bool direction = CCW;
if (ccw_angle < 0) ccw_angle += 360.0;
if (radius < 0)
direction = !direction;
path p = arc((0,0), fabs(radius), degrees(B-A), degrees(C-A), direction);
- real t = reltime(p, 0.5);
- pair P = midpoint(p);
- pair tangent = dir(p, t);
- if (direction == CW) tangent *= -1.0;
-
- pair label_rotate = tangent;
- if (rotateLabel == false)
- label_rotate = (1,0);
-
if (this.fill != invisible) {
path pcycle = (0,0) -- p -- cycle;
fill(picF, pcycle, this.fill);
}
draw(picF, p, this.outline);
- label(pic = picF,
- L = rotate(degrees(label_rotate)) * L,
- position = P + unit(P) * (pLabelSize.y / 2 + labelOffsetAdjustment));
+ if (direction == CW) {
+ p = reverse(p);
+ }
+ label(pic=picF, L=this.label, g=p);
add(pic, picF, A);
}
}
Pendulum makePendulum(pair pivot=(0,0), Mass mass=Mass(), real length=15mm, real angleDeg=0, Label angleL="", Label stringL="") {
mass.set_center(pivot + length*dir(angleDeg-90));
Pendulum p = Pendulum(pivot=pivot, mass=mass);
- p.angle.L = angleL;
+ p.angle.label = angleL;
p.str.L = stringL;
return p;
}