vs.push(ihat(center=(0,u)));
vs.push(jhat(center=(0,u)));
+vs.push(Vector(center=(-1u,-4u), phi=90, "Out"));
+vs.push(Vector(center=(-1u,-5.5u), phi=-90, "In"));
+vs.push(Vector(center=(0, -4u), mag=1.5u, dir=-90, phi=60, "60dg OOP"));
+
for (int i=0; i<ms.length; i+=1)
ms[i].draw();
for (int i=0; i<ds.length; i+=1)
struct Vector {
pair center;
real mag;
- real dir;
+ real dir; // angle in the plane of the drawing.
+ real phi; // angle with the plane of the drawing, 90 is out of the page.
pen outline;
Label L;
-
- void operator init(pair center=(0,0), real mag=5mm, real dir=0, pen outline=currentpen, Label L="") {
+ real out_of_plane_radius;
+ real out_of_plane_tolerance;
+
+ void operator init(pair center=(0,0), real mag=5mm, real dir=0, real phi=0, pen outline=currentpen, Label L="") {
this.center = center;
this.mag = mag;
this.dir = dir;
+ this.phi = phi;
this.outline = outline;
this.L = L;
+ this.out_of_plane_radius = 3mm;
+ this.out_of_plane_tolerance = 0.01;
}
pair pTip() {
void draw(picture pic=currentpicture, bool rotateLabel=false, pair labelOffset=(0,0)) {
picture picF;
- pair p = this.mag*dir(this.dir);
- path P = (0,0)--p;
- pair label_rotate = p;
- draw(picF, P, outline, Arrow);
- if (rotateLabel == false)
- label_rotate = (1,0);
+ pair p = (0,0);
+ pair label_rotate = (1,0);
+ pair label_align = (0,1);
+ real phi_e = this.phi % 360; // effective phi
+ if (this.mag < 0) (phi_e + 180) % 360;
+ if (Tan(phi_e) == 0 || abs(1.0/Tan(phi_e)) > this.out_of_plane_tolerance) {
+ // draw arrow in the plane of the drawing
+ // TODO: thickening for phi?
+ p = this.mag*Cos(this.phi)*dir(this.dir);
+ path P = (0,0)--p;
+ draw(picF, P, outline, Arrow);
+ if (rotateLabel == true)
+ label_rotate = p;
+ label_align = unit(rotate(90)*p);
+ } else if (phi_e > 0 && phi_e < 180) {
+ // draw a circled dot for out-of-the-page
+ p = (0, this.out_of_plane_radius);
+ draw(picF, scale(this.out_of_plane_radius)*unitcircle, outline);
+ dot(picF, (0,0), outline);
+ } else {
+ // draw a circled cross for into-the-page
+ real a = 0.8*sqrt(2.0)/2.0;
+ p = (0, this.out_of_plane_radius);
+ draw(picF, scale(this.out_of_plane_radius)*unitcircle, outline);
+ draw(picF, scale(this.out_of_plane_radius)*((-a,-a)--(a,a)), outline);
+ draw(picF, scale(this.out_of_plane_radius)*((-a,a)--(a,-a)), outline);
+ }
label(pic = picF,
L = rotate(degrees(label_rotate)) * L,
position = p+labelOffset,
- align = unit(rotate(90)*p));
+ align = label_align);
add(pic, picF, center);
}
}