Simplify Surface labeling to respect Label attributes in Mechanics.asy.
[course.git] / asymptote / Mechanics-test.asy
1 /* Test suite for Mechanics.asy.
2  *
3  * Copyright (C) 2008-2009 W. Trevor King <wking@drexel.edu>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 import Mechanics;
21
22 real u = 1cm;
23
24 LabeledCircle lc = LabeledCircle(center=(-2u, 1u));
25 lc.draw();
26 lc.label = "a";
27 lc.center = (-2u, 0.5u);
28 lc.draw();
29 lc.draw_label(Label("e", align=E));
30 lc.center = (-2u, 0);
31 lc.label.align = W;
32 lc.draw();
33 lc.draw_label("b");
34 lc.draw_label(Label("c", align=E));
35 lc.draw_label(rotate(90)*Label("e------I", align=S));
36 lc.draw_label(rotate(45)*Label("e------I", align=S));
37 lc.center = (-2u, -2u);
38 lc.radius = u/2;
39 lc.label.align = E;
40 lc.draw();
41 lc.center = (-2u, -3u);
42 lc.label.align = E;
43 lc.draw();
44
45 Mass a = Mass(center=(0,0));
46 Mass b = Mass(center=(2u,1u), Label("$m_b$", align=N));
47 Mass c = Mass(center=(1u,-2u), Label("$m_c$", align=E));
48 Mass ms[] = {a,b, c};
49 Distance dab = Distance(b.center(), a.center(), scale=u,
50     L=Label("$r_{ab}$", embed=Shift));
51 Distance dac = Distance(a.center(), c.center(), scale=u, L="$r_{ac}$");
52 Distance ds[] = {dab, dac};
53 Angle bac1 = Angle(
54     b.center(), a.center(), c.center(), radius=.7u, fill=red, L="$\theta_T'$");
55 Angle bac2 = Angle(
56     b.center(), a.center(), c.center(), radius=-.5u, L="$\theta_T$");
57 Angle bac3 = Angle(
58     b.center(), a.center(), c.center(), radius=1.5u,
59     L=Label("$\theta_T''$", position=Relative(0.3)));
60 Angle as[] = {bac1, bac2, bac3};
61
62 Vector vs[];
63
64 draw_ijhat((-u, u));
65
66 vs.push(Vector(center=(-1u,-4u), phi=90, "Out"));
67 vs.push(Vector(center=(-1u,-5.5u), phi=-90, "In"));
68 vs.push(Vector(center=(0, -4u), mag=1.5u, dir=-90, phi=60,
69                Label("60dg OOP", position=EndPoint)));
70
71 for (int i=0; i<as.length; i+=1)
72   as[i].draw();
73 for (int i=0; i<ms.length; i+=1)
74   ms[i].draw();
75 for (int i=0; i<ds.length; i+=1)
76   ds[i].draw();
77 for (int i=0; i<vs.length; i+=1)
78   vs[i].draw();
79
80 Pendulum p = makePendulum(
81     pivot=(3.5u,-3u), mass=b, length=4u, angleDeg=-20,
82     angleL="$\rho$", stringL=Label("r", embed=Shift));
83
84 real len = abs(p.pivot.x-b.center().x);
85 Spring s = Spring(pFrom=b.center()-(2u,0), pTo=b.center(), L="$k_1$");
86 s.draw();
87 s = Spring(pFrom=b.center(), pTo=(p.pivot.x, b.center().y), L="$k_2$");
88 s.draw();
89
90 p.draw(drawVertical=true);
91
92 Surface s = Surface(pFrom=(0,-7u), pTo=(3.5u, -7u),
93     L=Label("Table", align=Center, embed=Shift));
94 s.draw();
95
96 Vector v1 = Vector((-2u, -7u), Label("$v_1$", align=E, position=EndPoint));
97 v1.draw();
98 Vector v2 = Vector(v1.center, mag=10mm, dir=90, Label("$v_2$", align=W));
99 v2.draw();
100 Vector v3 = v1 + v2;
101 v3.label = Label("$v_3 = v_1 + v_2$", align=E, position=EndPoint);
102 v3.draw();
103 Vector v4 = v1 - v2;
104 v4.label = Label("$v_4 = v_1 - v_2$", align=S, position=EndPoint);
105 v4.draw();
106
107 Vector v = Velocity();
108 pair vfc = (5u,0);  // vector field center
109 real vfwidth = 2u;
110 real vfheight = 2u;
111 real vfdv = u/3;
112 real vfbuf = 2pt;
113
114 draw(shift(vfc)*xscale(vfwidth-2*vfbuf)*yscale(vfheight-2*vfbuf)
115      *shift((-.5,-.5))*unitsquare, grey);
116 vector_field(vfc, width=vfwidth, height=vfheight, dv=vfdv, buf=vfbuf, v=v,
117              outline=green+dashed);
118
119 vfc -= (0, vfheight + u);
120 v.dir = 90;
121 draw(shift(vfc)*xscale(vfwidth-2*vfbuf)*yscale(vfheight-2*vfbuf)
122      *shift((-.5,-.5))*unitsquare, grey);
123 vector_field(vfc, width=vfwidth, height=vfheight, dv=vfdv, buf=vfbuf, v=v,
124              outline=green+dashed);
125
126 vfc -= (0, vfheight + u);
127 v.dir = -180;
128 draw(shift(vfc)*xscale(vfwidth-2*vfbuf)*yscale(vfheight-2*vfbuf)
129      *shift((-.5,-.5))*unitsquare, grey);
130 vector_field(vfc, width=vfwidth, height=vfheight, dv=vfdv, buf=vfbuf, v=v,
131              outline=green+dashed);
132
133 vfc += (vfwidth + u, 2*(vfheight + u));
134 v.dir = -90;
135 draw(shift(vfc)*xscale(vfwidth-2*vfbuf)*yscale(vfheight-2*vfbuf)
136      *shift((-.5,-.5))*unitsquare, grey);
137 vector_field(vfc, width=vfwidth, height=vfheight, dv=vfdv, buf=vfbuf, v=v,
138              outline=green+dashed);
139
140 vfc -= (0, vfheight + u);
141 v.dir = -10;
142 draw(shift(vfc)*xscale(vfwidth-2*vfbuf)*yscale(vfheight-2*vfbuf)
143      *shift((-.5,-.5))*unitsquare, grey);
144 vector_field(vfc, width=vfwidth, height=vfheight, dv=vfdv, buf=vfbuf, v=v,
145              outline=green+dashed);
146
147 vfc -= (0, vfheight + u);
148 v.phi = 90;
149 draw(shift(vfc)*xscale(vfwidth-2*vfbuf)*yscale(vfheight-2*vfbuf)
150      *shift((-.5,-.5))*unitsquare, grey);
151 vector_field(vfc, width=vfwidth, height=vfheight, dv=vfdv, buf=vfbuf, v=v,
152              outline=green+dashed);