Commit ceb47f99 authored by Matija Obreza's avatar Matija Obreza
Browse files

Vectors

parent 6d1f7d18
class Vector {
private v: number[];
public constructor(x: number = 0, y: number = 0, z: number = 0) {
this.v = [x, y, z];
}
public length(): number {
return Math.sqrt(this.v[0] * this.v[0] + this.v[1] * this.v[1] + this.v[2] * this.v[2]);
}
public diff(b: Vector): Vector {
return new Vector(this.v[0] - b.v[0], this.v[1] - b.v[1], this.v[2] - b.v[2]);
}
public toString() {
return '(' + this.v[0] + ', ' + this.v[1] + ', ' + this.v[2] + ')';
}
public static distance(a: Vector, b: Vector): number {
const d = [a.v[0] - b.v[0], a.v[1] - b.v[1], a.v[2] - b.v[2]];
return Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
}
};
export { Vector as default };
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment