1 /* Test suite for Mechanics.asy.
3 * Copyright (C) 2008-2009 W. Trevor King <wking@drexel.edu>
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.
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.
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.
24 LabeledCircle lc = LabeledCircle(center=(-2u, 1u));
27 lc.center = (-2u, 0.5u);
29 lc.draw_label(Label("e", align=E));
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);
41 lc.center = (-2u, -3u);
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));
49 Distance dab = Distance(a.center(), b.center(), scale=u, L="$r_{ab}$");
50 Distance dac = Distance(a.center(), c.center(), scale=u, L="$r_{ac}$");
51 Distance ds[] = {dab, dac};
53 b.center(), a.center(), c.center(), radius=.7u, fill=red, L="$\theta_T'$");
55 b.center(), a.center(), c.center(), radius=-.5u, L="$\theta_T$");
56 Angle as[] = {bac1, bac2};
60 vs.push(ihat(center=(0,u)));
61 vs.push(jhat(center=(0,u)));
63 vs.push(Vector(center=(-1u,-4u), phi=90, "Out"));
64 vs.push(Vector(center=(-1u,-5.5u), phi=-90, "In"));
65 vs.push(Vector(center=(0, -4u), mag=1.5u, dir=-90, phi=60, "60dg OOP"));
67 for (int i=0; i<as.length; i+=1)
69 for (int i=0; i<ms.length; i+=1)
71 for (int i=0; i<ds.length; i+=1)
73 for (int i=0; i<vs.length; i+=1)
76 Pendulum p = makePendulum(pivot=(3.5u,-3u), mass=b, length=4u, angleDeg=-20,
77 angleL="$\rho$", stringL="r");
79 real len = abs(p.pivot.x-b.center().x);
80 Spring s = Spring(pFrom=b.center()-(2u,0), pTo=b.center(), L="$k_1$");
82 s = Spring(pFrom=b.center(), pTo=(p.pivot.x, b.center().y), L="$k_2$");
85 p.draw(drawVertical=true);
87 Surface s = Surface(pFrom=(0,-7u), pTo=(3.5u, -7u), L="Table");
91 Vector v = Velocity();
92 pair vfc = (5u,0); // vector field center
98 draw(shift(vfc)*xscale(vfwidth-2*vfbuf)*yscale(vfheight-2*vfbuf)
99 *shift((-.5,-.5))*unitsquare, grey);
100 vector_field(vfc, width=vfwidth, height=vfheight, dv=vfdv, buf=vfbuf, v=v,
101 outline=green+dashed);
103 vfc -= (0, vfheight + u);
105 draw(shift(vfc)*xscale(vfwidth-2*vfbuf)*yscale(vfheight-2*vfbuf)
106 *shift((-.5,-.5))*unitsquare, grey);
107 vector_field(vfc, width=vfwidth, height=vfheight, dv=vfdv, buf=vfbuf, v=v,
108 outline=green+dashed);
110 vfc -= (0, vfheight + u);
112 draw(shift(vfc)*xscale(vfwidth-2*vfbuf)*yscale(vfheight-2*vfbuf)
113 *shift((-.5,-.5))*unitsquare, grey);
114 vector_field(vfc, width=vfwidth, height=vfheight, dv=vfdv, buf=vfbuf, v=v,
115 outline=green+dashed);
117 vfc += (vfwidth + u, 2*(vfheight + u));
119 draw(shift(vfc)*xscale(vfwidth-2*vfbuf)*yscale(vfheight-2*vfbuf)
120 *shift((-.5,-.5))*unitsquare, grey);
121 vector_field(vfc, width=vfwidth, height=vfheight, dv=vfdv, buf=vfbuf, v=v,
122 outline=green+dashed);
124 vfc -= (0, vfheight + u);
126 draw(shift(vfc)*xscale(vfwidth-2*vfbuf)*yscale(vfheight-2*vfbuf)
127 *shift((-.5,-.5))*unitsquare, grey);
128 vector_field(vfc, width=vfwidth, height=vfheight, dv=vfdv, buf=vfbuf, v=v,
129 outline=green+dashed);
131 vfc -= (0, vfheight + u);
133 draw(shift(vfc)*xscale(vfwidth-2*vfbuf)*yscale(vfheight-2*vfbuf)
134 *shift((-.5,-.5))*unitsquare, grey);
135 vector_field(vfc, width=vfwidth, height=vfheight, dv=vfdv, buf=vfbuf, v=v,
136 outline=green+dashed);