Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 935x 935x 935x 935x 867x 867x 867x 867x 867x 867x 867x 935x 1x 1x 828x 828x 1x 1x 1x 1x 1x 19413x 212x 212x 212x 212x 212x 212x 212x 212x 212x 212x 212x 212x 212x 212x 1x 1x 19413x 178x 178x 178x 178x 178x 178x 178x 178x 178x 178x 178x 178x 178x 178x 1x 1x 19413x 1x 1x 19413x 1x 1x 8x 8x 1x 1x 14x 1x 1x 1376x 1376x 1376x 1376x 1376x 1376x 1376x 1376x 1376x 1376x 1376x 1376x 1376x 1x | /*----------------------------------------------------------------------+
| Title: PlaneElement.ts |
| A port of the software Geometry Applet by |
| Author: David E. Joyce |
| Department of Mathematics and Computer Science |
| Clark University |
| Worcester, MA 01610-1477 |
| U.S.A. |
| |
| http://aleph0.clarku.edu/~djoyce/home.html |
| djoyce@clarku.edu |
| |
| Date: February, 1996. Version 2.0.0 May, 1997. |
| TypeScript Port: 2019, Nelson Brown, brownnrl@gmail.com |
| https://www.nelsonbrown.net/ |
+----------------------------------------------------------------------*/
import {GeomElement} from "../GeomElement";
import {PointElement} from "../point/PointElement";
import {SlateCanvas} from "../../Slate";
export interface IPlaneElementConstruction {
A : PointElement;
B : PointElement;
C : PointElement;
}
type iplec = IPlaneElementConstruction
export class PlaneElement extends GeomElement {
/*--------------------------------------------------------------------+
| The plane is represented by three points on it. It's displayed as |
| a parallelogram with three vertices A, B, and C,projected onto the |
| xy-plane. S is a unit vector in the direction AB, T is a |
| perpendicular unit in the plane, and U is perpendicular to both. |
+--------------------------------------------------------------------*/
public A : PointElement;
public B : PointElement;
public C : PointElement;
public S : PointElement;
public T : PointElement;
public U : PointElement;
public pivot : PointElement; // pivot point for the plane, if any
public isScreen : boolean; // set true only for initial screen plane
constructor(ip? : IPlaneElementConstruction) {
super();
this.dimension = 2;
this.isScreen = false;
if (ip != null) {
this.A = ip.A;
this.B = ip.B;
this.C = ip.C;
this.S = new PointElement();
this.T = new PointElement();
this.U = new PointElement();
}
}
public defined(): boolean {
return this.A != null && this.B != null && this.C != null;
}
// A plane renders as a parallelogram with corners A, B, D, C
// where D = B + C - A (the 4th corner in the plane of A, B, C).
public drawEdge(c: SlateCanvas): void {
if (this.edgeColor == null || !this.defined()) return;
let ctx = c.getContext("2d") as CanvasRenderingContext2D;
ctx.save();
ctx.strokeStyle = this.edgeColor;
let dx = this.B.x + this.C.x - this.A.x;
let dy = this.B.y + this.C.y - this.A.y;
ctx.beginPath();
ctx.moveTo(this.A.x, this.A.y);
ctx.lineTo(this.B.x, this.B.y);
ctx.lineTo(dx, dy);
ctx.lineTo(this.C.x, this.C.y);
ctx.closePath();
ctx.stroke();
ctx.restore();
}
public drawFace(c: SlateCanvas): void {
if (this.faceColor == null || !this.defined()) return;
let ctx = c.getContext("2d") as CanvasRenderingContext2D;
ctx.save();
ctx.fillStyle = this.faceColor;
let dx = this.B.x + this.C.x - this.A.x;
let dy = this.B.y + this.C.y - this.A.y;
ctx.beginPath();
ctx.moveTo(this.A.x, this.A.y);
ctx.lineTo(this.B.x, this.B.y);
ctx.lineTo(dx, dy);
ctx.lineTo(this.C.x, this.C.y);
ctx.closePath();
ctx.fill();
ctx.restore();
}
public drawName(c: SlateCanvas): void {
if (this.nameColor == null || this.name == null || !this.defined()) return;
// Label placed at midpoint of BC, matching Java PlaneElement.drawName
let ix = Math.round((this.B.x + this.C.x) / 2.0);
let iy = Math.round((this.B.y + this.C.y) / 2.0);
this.drawString(ix, iy, c);
}
public drawVertex(c: SlateCanvas): void {
if (this.vertexColor == null || !this.defined()) return;
// Draw vertex at D = B + C - A (the 4th parallelogram corner).
// A, B, C are drawn by their own drawVertex calls in Slate.
let ctx = c.getContext("2d") as CanvasRenderingContext2D;
let dx = this.B.x + this.C.x - this.A.x;
let dy = this.B.y + this.C.y - this.A.y;
ctx.beginPath();
ctx.fillStyle = this.vertexColor;
ctx.arc(dx, dy, 2, 0, 2*Math.PI, false);
ctx.fill();
}
public rotate(pivot: PointElement, ac: number, as: number): void {
this.update();
}
public translate(dx: number, dy: number): void {
}
public update(): void {
if (this.isScreen && (this.A.z!=0.0 || this.B.z!=0.0 || this.C.z!=0.0))
this.isScreen = false;
// update the frame S,T,U
this.S.to(this.B).minus(this.A);
this.T.to(this.C).minus(this.A);
this.S.times(1.0/this.S.length());
let st : number = PointElement.dot(this.T, this.S);
this.T.x -= st*this.S.x;
this.T.y -= st*this.S.y;
this.T.z -= st*this.S.z;
this.T.times(1.0/this.T.length());
this.U.toCross(this.S,this.T);
}
}
|