This commit is contained in:
2026-08-19 17:17:46 +02:00
parent a40f10ab22
commit 2ae236cc67
5 changed files with 64 additions and 25 deletions
+9
View File
@@ -38,9 +38,14 @@ export default class Vec2d implements Point {
normalize(): Vec2d {
const len = this.length();
if (len === 0) return new Vec2d(0, 0); // avoid division by zero
return new Vec2d(this.x / len, this.y / len);
}
neg(): Vec2d {
return new Vec2d(-this.x, -this.y);
}
scale(scalar: number): Vec2d {
return new Vec2d(this.x * scalar, this.y * scalar);
}
@@ -61,6 +66,10 @@ export default class Vec2d implements Point {
return this.sub(other).length();
}
dot(other: Vec2d): number {
return this.x * other.x + this.y * other.y;
}
lerp(other: Vec2d, t: number): Vec2d {
// (1-t)*A + B*t
return this.scale(1 - t).add(other.scale(t));