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

rotation matrix

parent dc08c5c9
No related branches found
No related tags found
No related merge requests found
import Playground from "./playground"; import Playground from "./playground";
import { vecNormalize } from "./utils"; import * as Utils from './utils';
import { vecLength } from "./utils";
import { vecDotProduct } from "./utils";
import { vecAngle } from "./utils";
import { vecCrossProduct } from "./utils";
import { multVecMatrix } from "./utils";
const pg = new Playground(); const pg = new Playground();
...@@ -13,34 +8,19 @@ const v = [1,1,1] ...@@ -13,34 +8,19 @@ const v = [1,1,1]
// Some matrices // 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); // Calculations
const vn = multVecMatrix(v, n); const vx = Utils.multVecMatrix(v, Utils.rotX(45));
const vo = multVecMatrix(v, o); const vy = Utils.multVecMatrix(v, Utils.rotY(45));
const vz = Utils.multVecMatrix(v, Utils.rotZ(45));
// Visualize // Visualize
pg.gridXZ(); // Grid pg.gridXZ(); // Grid
pg.visVector(v,{color:"black",label:"V"}); pg.visVector(v,{color:"black",label:"V"});
pg.visVector(vm,{color:"red",label:"VM"}); pg.visVector(vx,{color:"red",label:"VX"});
pg.visVector(vn,{color:"green",label:"VN"}); pg.visVector(vy,{color:"green",label:"VY"});
pg.visVector(vo,{color:"blue",label:"VO"}); pg.visVector(vz,{color:"blue",label:"VZ"});
...@@ -95,4 +95,31 @@ export function multVecMatrix(v: Array<number>, m: Array<number>){ ...@@ -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] 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment