diff --git a/src/cg/testing.ts b/src/cg/testing.ts index 14dc78b9442bb821b3c7f873a3a3a32944f197b8..28f89140221143ec3e6616630d06b4424d8b4be9 100644 --- a/src/cg/testing.ts +++ b/src/cg/testing.ts @@ -1,10 +1,5 @@ import Playground from "./playground"; -import { vecNormalize } from "./utils"; -import { vecLength } from "./utils"; -import { vecDotProduct } from "./utils"; -import { vecAngle } from "./utils"; -import { vecCrossProduct } from "./utils"; -import { multVecMatrix } from "./utils"; +import * as Utils from './utils'; const pg = new Playground(); @@ -13,34 +8,19 @@ const v = [1,1,1] // 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); +// Calculations +const vx = Utils.multVecMatrix(v, Utils.rotX(45)); +const vy = Utils.multVecMatrix(v, Utils.rotY(45)); +const vz = Utils.multVecMatrix(v, Utils.rotZ(45)); // Visualize pg.gridXZ(); // Grid 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"}); +pg.visVector(vx,{color:"red",label:"VX"}); +pg.visVector(vy,{color:"green",label:"VY"}); +pg.visVector(vz,{color:"blue",label:"VZ"}); + + diff --git a/src/cg/utils.ts b/src/cg/utils.ts index 4750d92d0f0c84ffdf4457d6d0c3d4b88ecef3ae..69af7d1f68baf103488faff7daa66bb952a38034 100644 --- a/src/cg/utils.ts +++ b/src/cg/utils.ts @@ -95,4 +95,31 @@ export function multVecMatrix(v: Array<number>, m: Array<number>){ 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] ] } + +export function rotX(degrees: number){ + const radian = degrees * Math.PI / 180 + return [ + 1, 0, 0, + 0, Math.cos(radian), Math.sin(radian), + 0, -1*Math.sin(radian), Math.cos(radian) + ] +} + +export function rotY(degrees: number){ + const radian = degrees * Math.PI / 180 + return [ + Math.cos(radian), 0, -1*Math.sin(radian), + 0, 1, 0, + Math.sin(radian), 0, Math.cos(radian) + ] +} + +export function rotZ(degrees: number){ + const radian = degrees * Math.PI / 180 + return [ + Math.cos(radian), Math.sin(radian), 0, + -1*Math.sin(radian), Math.cos(radian), 0, + 0, 0, 1 + ] +} // \ No newline at end of file