Zoomable Canvas

This commit is contained in:
Emma
2023-02-15 17:45:37 -07:00
parent fbcffcde27
commit c767c09776
7 changed files with 623 additions and 38 deletions

View File

@@ -2,7 +2,7 @@
import { Constants } from "./constants.ts";
export class Vector {
export class Vector implements Point {
x: number;
y: number;
z: number;
@@ -278,3 +278,34 @@ export class Vector {
return Vector.dot(Vector.sub(a, b), Vector.sub(a, b))
}
}
export class OriginVector extends Vector {
origin: Point;
get halfwayPoint() {
return {
x: (this.mag()/2 * Math.sin(this.heading())) + this.origin.x,
y: (this.mag()/2 * Math.cos(this.heading())) + this.origin.y
}
}
constructor(origin: Point, p: Point) {
super(p.x, p.y, p.z);
this.origin = origin;
}
static from(origin: Point, p: Point) {
const v = {
x: p.x - origin.x,
y: p.y - origin.y,
};
return new OriginVector(origin, v);
}
}
export interface Point {
x: number;
y: number;
z?: number;
}