-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.js
More file actions
31 lines (27 loc) · 705 Bytes
/
Copy pathmatrix.js
File metadata and controls
31 lines (27 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* A basic matrix class
* @param {number} rows The number of rows in the matrix
* @param {number} columns The number of columns in the matrix
*/
function Matrix(rows,columns){
this.rows=rows;
this.columns=columns;
this.data=[];
for(let i=0;i<this.rows;i++){
this.data[i]=[];
for(let j=0;j<this.columns;j++){
this.data[i][j]=0;
}
}
}
/**
* Multiplies the matrix by a vector
* @param {Vector} vector The vector to multiply the matrix by
* @returns Vector
*/
Matrix.prototype.multiplyVector=function(vector){
let result=new Vector(0,0);
result.x=this.data[0][0]*vector.x + this.data[0][1]*vector.y;
result.y=this.data[1][0]*vector.x+this.data[1][1]*vector.y;
return result;
}