import graph3;
import three;
import settings;
outformat="pdf";
settings.render = 0;
settings.prc = false;
usepackage("fourier");
defaultpen(font("T1","fut\textfamilyextension","m","n"));
size(300, 300);
// Set the camera.
currentprojection=perspective(16,-8,4);
void drawArrowX()
{
real x0 = 12.8;
real halfWidth = 0.02;
real lineLength = 0.5;
real arrowHalfWidth = 0.10;
real arrowLength = 0.2;
draw(
(x0,-halfWidth,0)
-- (x0 + lineLength,-halfWidth,0)
-- (x0 + lineLength,-halfWidth - arrowHalfWidth,0)
-- (x0 + lineLength + arrowLength,0,0)
-- (x0 + lineLength,halfWidth + arrowHalfWidth,0)
-- (x0 + lineLength,halfWidth,0)
-- (x0,halfWidth,0)
-- cycle );
}
void drawArrowY(real x, real v)
{
real arrowHalfWidth = 0.07;
real arrowLength = 0.2;
real absV = abs(v);
real dir = v / absV;
real newV = dir * (absV - arrowLength);
draw( (x, 0, 0) -- (x, newV, 0));
draw(
( x - arrowHalfWidth, newV, 0)
-- ( x, v, 0)
-- ( x + arrowHalfWidth, newV, 0)
-- cycle );
}
void drawArrowZ(real x, real v)
{
real arrowHalfWidth = 0.07;
real arrowLength = 0.2;
real absV = abs(v);
real dir = v / absV;
real newV = dir * (absV - arrowLength);
draw( (x, 0, 0) -- (x, 0, newV));
draw(
( x - arrowHalfWidth, 0, newV)
-- ( x, 0, v)
-- ( x + arrowHalfWidth, 0, newV)
-- cycle );
}
void drawSineArrowsY(int i)
{
real x;
real z;
x = pi * i + pi * 0.1;
z = -2 * sin(x);
drawArrowY(x, z);
x = pi * i + pi * 0.3;
z = -2 * sin(x);
drawArrowY(x, z);
x = pi * i + pi * 0.5;
z = -2 * sin(x);
drawArrowY(x, z);
x = pi * i + pi * 0.7;
z = -2 * sin(x);
drawArrowY(x, z);
x = pi * i + pi * 0.9;
z = -2 * sin(x);
drawArrowY(x, z);
}
void drawSineArrowsZ(int i)
{
real x;
real z;
x = pi * i + pi * 0.1;
z = 2 * sin(x);
drawArrowZ(x, z);
x = pi * i + pi * 0.3;
z = 2 * sin(x);
drawArrowZ(x, z);
x = pi * i + pi * 0.5;
z = 2 * sin(x);
drawArrowZ(x, z);
x = pi * i + pi * 0.7;
z = 2 * sin(x);
drawArrowZ(x, z);
x = pi * i + pi * 0.9;
z = 2 * sin(x);
drawArrowZ(x, z);
}
void drawArrowsY()
{
drawSineArrowsY(0);
drawSineArrowsY(1);
drawSineArrowsY(2);
drawSineArrowsY(3);
}
void drawArrowsZ()
{
drawSineArrowsZ(0);
drawSineArrowsZ(1);
drawSineArrowsZ(2);
drawSineArrowsZ(3);
}
void drawLambdaBarX()
{
real x0 = pi * 0.5;
real x1 = pi * 2.5;
real m = 0.5 * (x1 + x0);
real z = 2.3;
real halfWidth = 0.07;
draw( (x0, 0.0, z) -- (x1, 0.0, z) );
draw( (x0, 0.0, z - halfWidth) -- (x0, 0.0, z + halfWidth) );
draw( (x1, 0.0, z - halfWidth) -- (x1, 0.0, z + halfWidth) );
draw("$\lambda$",(m,0,2.6));
}
real x1(real x) {return x;}
real y1(real x) {return 0.0;}
real z1(real x) {return 2.0 * sin(x);}
real x2(real x) {return x;}
real y2(real x) {return -2.0 * sin(x);}
real z2(real x) {return 0.0;}
// Draw the arrows.
drawArrowX();
drawArrowsY();
drawArrowsZ();
// Draw the sines.
draw(graph(x1,y1,z1,0.0,4pi));
draw(graph(x2,y2,z2,0.0,4pi));
// Draw the wave length meter.
drawLambdaBarX();
draw("$\vec E$",(10,0,-2));
draw("$\vec B$",(12,0,1.5));