5b761f43390426bab9fe954b2062816cf1a899ac
[course.git] / asymptote / ElectroMag-test.asy
1 /* Test suite for ElectroMag.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 ElectroMag;
21
22 real u = 1cm;
23
24 Charge a = pCharge(center=(0.5u,2u));
25 Charge b = aCharge(center=(0,-0.5u), q=1);
26 Charge c = nCharge(center=(-3u,-0.5u), q=-3);
27 Charge cs[] = {a,b,c};
28 Distance dab = Distance(b.center(), a.center(), scale=u, L="$r_1$");
29 Distance dbc = Distance(c.center(), b.center(), scale=u, L="$r_2$");
30 Distance ds[] = {dab};
31 Angle abc = Angle(
32     a.center(), b.center(), c.center(), radius=.5u, L="$\theta_T$");
33 Angle bac = Angle(
34     b.center(), a.center(), c.center(), radius=-0.4u, L="$\phi_x$");
35 Angle as[] = {abc, bac};
36
37 //write(a.center.x);
38 //write(a.center.y);
39 for (int i=0; i<cs.length; i+=1)
40   cs[i].draw();
41 for (int i=0; i<ds.length; i+=1)
42   ds[i].draw();
43 for (int i=0; i<as.length; i+=1)
44   as[i].draw();
45
46 CoulombEFields((-0.5u, 1.2u), c=cs, scale=2u, unit=u/2);
47 //Vector Fba = CoulombForce(b,a, scale=2u, unit=u);
48 //Fba.draw();
49 CoulombForces(c=cs, scale=2u, unit=u);
50
51 Charge a = aCharge(center=(-2u, 2u), q=0);
52 a.draw();
53 Vector v = EField(a.center(), mag=u/2, dir=0,L="E"); v.draw();
54 Vector v = BField(a.center(), mag=u/2, dir=90,L="B"); v.draw();
55 Vector v = Velocity(a.center(), mag=u/2, dir=180,L="$v$"); v.draw();
56
57 Vector Ic = Current(center=(-0.7u, 2.2u), phi=90, L="$I$"); Ic.draw();
58 draw(shift(Ic.center)*scale(16pt)*unitcircle, BFieldPen, ArcArrow);
59
60 a = aCharge(center=(-3u, 2u), q=-1);
61 a.draw();