-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.js
43 lines (35 loc) · 848 Bytes
/
matrix.js
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
32
33
34
35
36
37
38
39
40
41
42
43
//function for create matrix
function createMatrix(cols, rows)
{
var matrix = new Array(cols);
for(var i = 0 ; i < cols ; i++)
{
matrix[i] = new Array(rows);
}
for(var i = 0 ; i < cols ; i++)
{
for(var j = 0 ; j < rows ; j++)
{
matrix[i][j]=0;
}
}
return matrix;
}
//function for multyplying 3Dvector by matrix 3x3
function multVecByMat(vector, matrix)
{
var newVector = new Vector(0,0,0);
var a = vector.x * matrix[0][0];
var b = vector.y * matrix[0][1];
var c = vector.z * matrix[0][2];
newVector.x = a+b+c;
a = vector.x * matrix[1][0];
b = vector.y * matrix[1][1];
c = vector.z * matrix[1][2];
newVector.y = a+b+c;
a = vector.x * matrix[2][0];
b = vector.y * matrix[2][1];
c = vector.z * matrix[2][2];
newVector.z = a+b+c;
return newVector;
}