initial commit
This commit is contained in:
commit
e8c3f9862a
193 files changed
+29795
No files matched your search
@@ -0,0 +1,67 @@
|
||||
export class Vector2D {
|
||||
constructor(x = 0, y = 0) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
mulS(scalar) {
|
||||
return new Vector2D(this.x * scalar, this.y * scalar);
|
||||
}
|
||||
|
||||
mulV(vector) {
|
||||
return new Vector2D(this.x * vector.x, this.y * vector.y);
|
||||
}
|
||||
|
||||
divS(scalar) {
|
||||
return new Vector2D(this.x / scalar, this.y / scalar);
|
||||
}
|
||||
|
||||
divV(vector) {
|
||||
return new Vector2D(this.x / vector.x, this.y / vector.y);
|
||||
}
|
||||
|
||||
addS(scalar) {
|
||||
return new Vector2D(this.x + scalar, this.y + scalar);
|
||||
}
|
||||
|
||||
addV(vector) {
|
||||
return new Vector2D(this.x + vector.x, this.y + vector.y);
|
||||
}
|
||||
|
||||
subS(scalar) {
|
||||
return new Vector2D(this.x - scalar, this.y - scalar);
|
||||
}
|
||||
|
||||
subV(vector) {
|
||||
return new Vector2D(this.x - vector.x, this.y - vector.y);
|
||||
}
|
||||
|
||||
dot(vector) {
|
||||
return this.x * vector.x + this.y * vector.y;
|
||||
}
|
||||
|
||||
abs() {
|
||||
return new Vector2D(Math.abs(this.x), Math.abs(this.y));
|
||||
}
|
||||
|
||||
length() {
|
||||
return Math.sqrt(this.dot(this));
|
||||
}
|
||||
|
||||
lengthSqrt() {
|
||||
return this.dot(this);
|
||||
}
|
||||
|
||||
normalize() {
|
||||
const length = this.length();
|
||||
this.x /= length;
|
||||
this.y /= length;
|
||||
return this;
|
||||
}
|
||||
|
||||
rotate(angle) {
|
||||
const cos = Math.cos(angle);
|
||||
const sin = Math.sin(angle);
|
||||
return new Vector2D(this.x * cos - this.y * sin, this.x * sin + this.y * cos);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user