diff --git a/src/cg/testing.ts b/src/cg/testing.ts index 60237e1e5f13e32f229ad02566bed663a777dd53..14dc78b9442bb821b3c7f873a3a3a32944f197b8 100644 --- a/src/cg/testing.ts +++ b/src/cg/testing.ts @@ -4,22 +4,43 @@ import { vecLength } from "./utils"; import { vecDotProduct } from "./utils"; import { vecAngle } from "./utils"; import { vecCrossProduct } from "./utils"; +import { multVecMatrix } from "./utils"; const pg = new Playground(); // Some vectors -const v = [1,0,1] -const w = [0,2,2] +const v = [1,1,1] -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 pg.gridXZ(); // Grid -pg.visVector(v,{color:"orange",label:"V"}); -pg.visVector(w,{color:"red",label:"W"}); -pg.visVector(cp,{color:"grey",label:"crossproduct"}) +pg.visVector(v,{color:"black",label:"V"}); +pg.visVector(vm,{color:"red",label:"VM"}); +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))); diff --git a/src/cg/utils.ts b/src/cg/utils.ts index db0243a22f7e6e79759e558f60f973e4ed9f04ca..4750d92d0f0c84ffdf4457d6d0c3d4b88ecef3ae 100644 --- a/src/cg/utils.ts +++ b/src/cg/utils.ts @@ -86,7 +86,13 @@ export function matrixProduct(a: Array<number>, b: Array<number>){ //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], //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