You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
782 B
38 lines
782 B
class Vector {
|
|
constructor(public x: number, public y: number) {}
|
|
|
|
copy(){
|
|
return new Vector(this.x, this.y);
|
|
}
|
|
|
|
static Add(v1: Vector, v2: Vector){
|
|
return new Vector(v1.x + v2.x, v1.y + v2.y);
|
|
}
|
|
static Sub(v1: Vector, v2: Vector){
|
|
return new Vector(v1.x - v2.x, v1.y - v2.y);
|
|
}
|
|
static Mult(v: Vector, n: number){
|
|
return new Vector(v.x * n, v.y * n);
|
|
}
|
|
|
|
add(v: Vector){
|
|
this.x += v.x;
|
|
this.y += v.y;
|
|
}
|
|
addC(x: number, y: number){
|
|
this.x += x;
|
|
this.y += y;
|
|
}
|
|
mult(n: number){
|
|
this.x *= n;
|
|
this.y *= n;
|
|
}
|
|
|
|
mag(){
|
|
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
}
|
|
|
|
normalize(){
|
|
this.mult(1 / this.mag());
|
|
}
|
|
} |