Skip to content
Snippets Groups Projects
Commit dc08c5c9 authored by Christoph-Anton Schwierz's avatar Christoph-Anton Schwierz
Browse files

multVecMatrix()

parent cbe30678
No related branches found
No related tags found
No related merge requests found
...@@ -4,22 +4,43 @@ import { vecLength } from "./utils"; ...@@ -4,22 +4,43 @@ import { vecLength } from "./utils";
import { vecDotProduct } from "./utils"; import { vecDotProduct } from "./utils";
import { vecAngle } from "./utils"; import { vecAngle } from "./utils";
import { vecCrossProduct } from "./utils"; import { vecCrossProduct } from "./utils";
import { multVecMatrix } from "./utils";
const pg = new Playground(); const pg = new Playground();
// Some vectors // Some vectors
const v = [1,0,1] const v = [1,1,1]
const w = [0,2,2]
const cp = vecCrossProduct(w, v); // Some matrices
const m = [
1,2,4,
4,5,6,
3,2,1
]
const n = [
1,4,3,
2,5,2,
4,6,1
]
const o = [
-3,-4,-5,
-2,-3,-6,
-1,-5,-4
]
// Calculations
const vm = multVecMatrix(v, m);
const vn = multVecMatrix(v, n);
const vo = multVecMatrix(v, o);
// Visualize // Visualize
pg.gridXZ(); // Grid pg.gridXZ(); // Grid
pg.visVector(v,{color:"orange",label:"V"}); pg.visVector(v,{color:"black",label:"V"});
pg.visVector(w,{color:"red",label:"W"}); pg.visVector(vm,{color:"red",label:"VM"});
pg.visVector(cp,{color:"grey",label:"crossproduct"}) pg.visVector(vn,{color:"green",label:"VN"});
pg.visVector(vo,{color:"blue",label:"VO"});
console.log("v length:" + vecLength(v));
console.log("w length:" + vecLength(w));
console.log("normalized dotProduct:" + vecDotProduct(vecNormalize(v), vecNormalize(w)));
...@@ -86,7 +86,13 @@ export function matrixProduct(a: Array<number>, b: Array<number>){ ...@@ -86,7 +86,13 @@ export function matrixProduct(a: Array<number>, b: Array<number>){
//row 2 //row 2
a[3]*b[0] + a[4]*b[3] + a[5]*b[6], a[3]*b[1] + a[4]*b[4] + a[5]*b[7], a[3]*b[2] + a[4]*b[5] + a[5]*b[8], a[3]*b[0] + a[4]*b[3] + a[5]*b[6], a[3]*b[1] + a[4]*b[4] + a[5]*b[7], a[3]*b[2] + a[4]*b[5] + a[5]*b[8],
//row 3 //row 3
a[6]*b[0] + a[7]*b[3] + a[8]*b[6], a[6]*b[1] + a[7]*b[4] + a[8]*b[7], a[6]*b[2] + a[7]*b[5] + a[8]*b[8], a[6]*b[0] + a[7]*b[3] + a[8]*b[6], a[6]*b[1] + a[7]*b[4] + a[8]*b[7], a[6]*b[2] + a[7]*b[5] + a[8]*b[8]
]
}
export function multVecMatrix(v: Array<number>, m: Array<number>){
return [
v[0]*m[0] + v[1]*m[3] + v[2]*m[6], v[0]*m[1] + v[1]*m[4] + v[2]*m[7], v[0]*m[2] + v[1]*m[5] + v[2]*m[8]
] ]
} }
// //
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment